<?php

namespace Database\Factories;

use App\Enums\Status;
use App\Models\ExpenseType;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ExpenseType>
 */
class ExpenseTypeFactory extends Factory
{
    protected $model = ExpenseType::class;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $categories = ['Travel', 'Office', 'Client', 'Training', 'Equipment', 'Medical', 'Admin'];
        $types = ['Expense', 'Cost', 'Fee', 'Allowance', 'Reimbursement'];

        $name = fake()->randomElement($categories).' '.fake()->randomElement($types).' '.fake()->unique()->numerify('###');

        return [
            'name' => $name,
            'code' => strtoupper(str_replace(' ', '_', substr($name, 0, 20))).'_'.fake()->unique()->numerify('###'),
            'notes' => fake()->optional()->sentence(),
            'default_amount' => fake()->optional()->randomFloat(2, 50, 500),
            'max_amount' => fake()->optional()->randomFloat(2, 500, 5000),
            'is_proof_required' => fake()->boolean(30),
            'status' => Status::ACTIVE,
        ];
    }

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

    /**
     * Indicate that the expense type is inactive.
     */
    public function inactive(): static
    {
        return $this->state(fn (array $attributes) => [
            'status' => Status::INACTIVE,
        ]);
    }

    /**
     * Indicate that proof is required for this expense type.
     */
    public function proofRequired(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_proof_required' => true,
        ]);
    }

    /**
     * Set a specific max amount for this expense type.
     */
    public function withMaxAmount(float $amount): static
    {
        return $this->state(fn (array $attributes) => [
            'max_amount' => $amount,
        ]);
    }
}
