<?php

namespace Database\Factories;

use App\Models\Branch;
use App\Models\Customer;
use App\Models\Loan;
use App\Models\LoanProduct;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/** @extends Factory<Loan> */
class LoanFactory extends Factory
{
    protected $model = Loan::class;

    public function definition(): array
    {
        $principal = 500000.00;
        $interest = 50000.00;

        return [
            'branch_id' => Branch::factory(),
            'customer_id' => Customer::factory(),
            'loan_product_id' => LoanProduct::factory(),
            'sequence_number' => $this->faker->unique()->numberBetween(1, 999999),
            'sequence_year' => (int) now()->format('Y'),
            'loan_number' => 'LN-TEST-'.strtoupper($this->faker->unique()->bothify('######??')),
            'principal' => $principal,
            'interest' => $interest,
            'processing_fee' => 0,
            'insurance_fee' => 0,
            'other_charges' => 0,
            'fees' => 0,
            'total_repayment' => $principal + $interest,
            'purpose' => 'Test loan',
            'schedule_start_date' => now()->toDateString(),
            'status' => 'draft',
            'created_by' => User::factory(),
        ];
    }
}
