<?php

namespace Database\Factories;

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

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\LoanReschedule>
 */
class LoanRescheduleFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $loan = Loan::factory()->create();

        return [
            'loan_id' => $loan->id,
            'reschedule_type' => $this->faker->randomElement(['extend_duration', 'change_rate', 'restructure']),
            'old_amount' => $loan->amount,
            'new_amount' => $this->faker->numberBetween(1000, 50000),
            'old_duration' => $loan->duration_months,
            'new_duration' => $this->faker->numberBetween(6, 36),
            'old_interest_rate' => $loan->interest_rate,
            'new_interest_rate' => $this->faker->randomFloat(2, 5, 25),
            'reschedule_date' => $this->faker->dateTimeBetween('-1 month', 'now'),
            'reason' => $this->faker->sentence(),
            'status' => $this->faker->randomElement(['pending', 'approved', 'rejected']),
            'approved_by' => $this->faker->optional()->randomElement(User::pluck('id')->toArray()),
            'approved_at' => $this->faker->optional()->dateTimeBetween('-1 month', 'now'),
            'approval_notes' => $this->faker->optional()->paragraph(),
        ];
    }
}
