<?php

namespace Database\Factories;

use App\Enums\InvoiceStatus;
use App\Models\Customer;
use App\Models\Invoice;
use App\Models\TaxRate;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;

class InvoiceFactory extends Factory
{
    protected $model = Invoice::class;

    public function definition(): array
    {
        $customer = Customer::all()->shuffle()->firstOrFail();

        return [
            'created_at'  => Carbon::now()->subDays(rand(1, 30)),
            'pst_rate'    => TaxRate::where('name', 'PST')->value('value') ?? 0,
            'gst_rate'    => TaxRate::where('name', 'GST')->value('value') ?? 0,
            'hst_rate'    => TaxRate::where('name', 'HST')->value('value') ?? 0,
            'has_gst'     => true,
            'has_pst'     => $this->faker->boolean(40),
            'has_hst'     => false,
            'date'        => Carbon::now()->subDays(rand(1, 60)),
            'status'      => InvoiceStatus::UNPAID->value,
            'customer_id' => $customer->id,
            'updated_at'  => Carbon::now(),
        ];
    }
}
