<?php

namespace Database\Factories;

use App\Enums\AgentStatus;
use App\Enums\CommissionType;
use App\Models\Agent;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<Agent>
 */
class AgentFactory extends Factory
{
    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'name' => fake()->name(),
            'company_name' => fake()->optional()->company(),
            'phone' => fake()->numerify('03#########'),
            'email' => fake()->boolean(70) ? fake()->unique()->safeEmail() : null,
            'address' => fake()->optional()->address(),
            'commission_type' => null,
            'commission_value' => null,
            'status' => AgentStatus::Active,
            'created_by' => User::factory(),
        ];
    }

    public function active(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => AgentStatus::Active,
        ]);
    }

    public function inactive(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => AgentStatus::Inactive,
        ]);
    }

    public function percentage(float $value = 2.5): static
    {
        return $this->state(fn (array $attributes): array => [
            'commission_type' => CommissionType::Percentage,
            'commission_value' => $value,
        ]);
    }
}
