<?php

namespace Database\Factories;

use App\Models\SavingsAccount;
use App\Models\Client;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SavingsAccount>
 */
class SavingsAccountFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'account_number' => 'SA-' . $this->faker->unique()->numberBetween(100000, 999999),
            'client_id' => Client::factory(),
            'product_name' => $this->faker->randomElement(['Regular Savings', 'Fixed Deposit', 'Voluntary Savings', 'Compulsory Savings']),
            'type' => $this->faker->randomElement(['regular', 'fixed', 'voluntary', 'compulsory']),
            'opening_balance' => $this->faker->numberBetween(1000, 10000),
            'current_balance' => $this->faker->numberBetween(1000, 10000),
            'minimum_balance' => $this->faker->numberBetween(100, 500),
            'interest_rate' => $this->faker->randomFloat(2, 1, 10),
            'interest_calculation' => $this->faker->randomElement(['daily', 'monthly', 'quarterly', 'annually']),
            'opening_date' => $this->faker->date(),
            'maturity_date' => $this->faker->optional()->date(),
            'status' => $this->faker->randomElement(['active', 'inactive', 'dormant', 'closed']),
            'notes' => $this->faker->optional()->sentence(),
            'created_by' => User::factory(),
            'approved_by' => User::factory(),
            'approved_at' => $this->faker->optional()->dateTime(),
        ];
    }

    /**
     * Indicate that the savings account is active.
     */
    public function active(): static
    {
        return $this->state(fn (array $attributes) => [
            'status' => 'active',
        ]);
    }

    /**
     * Indicate that the savings account is for a specific client.
     */
    public function forClient($clientId): static
    {
        return $this->state(fn (array $attributes) => [
            'client_id' => $clientId,
        ]);
    }
}
