<?php

namespace Database\Factories;

use App\Enums\CommissionType;
use Illuminate\Database\Eloquent\Factories\Factory;

class PartnerFactory extends Factory
{
    public function definition(): array
    {
        $commissionType = fake()->randomElement(CommissionType::cases());

        return [
            'name'                     => fake()->randomElement(['Warung', 'Toko', 'Kedai', 'Dapur']) . ' ' . fake()->firstName(),
            'phone'                    => '08' . fake()->numerify('#########'),
            'address'                  => 'RT ' . fake()->numberBetween(1, 10) . '/RW ' . fake()->numberBetween(1, 5) . ' Desa Budiharja',
            'notes'                    => fake()->optional(0.4)->sentence(),
            'default_commission_type'  => $commissionType->value,
            'default_commission_value' => $commissionType === CommissionType::Percent
                ? fake()->randomElement([5, 8, 10, 12, 15])
                : fake()->randomElement([1000, 1500, 2000, 2500, 3000]),
            'is_active'                => true,
        ];
    }

    public function inactive(): static
    {
        return $this->state(fn () => ['is_active' => false]);
    }

    public function percentCommission(float $value = 10): static
    {
        return $this->state(fn () => [
            'default_commission_type'  => CommissionType::Percent->value,
            'default_commission_value' => $value,
        ]);
    }

    public function fixedCommission(float $value = 2000): static
    {
        return $this->state(fn () => [
            'default_commission_type'  => CommissionType::Fixed->value,
            'default_commission_value' => $value,
        ]);
    }
}
