<?php

namespace Database\Factories;

use App\Models\Contract;
use App\Models\Product;
use Illuminate\Database\Eloquent\Factories\Factory;

class ContractFactory extends Factory
{
    protected $model = Contract::class;

    public function definition(): array
    {
        return [
            'product_id' => Product::factory(),
            'contract_number' => 'HDMB-' . $this->faker->unique()->numberBetween(10000, 99999),
            'contract_type' => 'HĐMB',
            'signing_date' => $this->faker->date(),
            'status' => 'Đang hiệu lực',
            'total_value' => fn (array $attributes) => Product::find($attributes['product_id'])->total_price,
            'paid_amount' => function (array $attributes) {
                $total = Product::find($attributes['product_id'])->total_price;
                return $this->faker->randomFloat(2, 0, $total);
            },
            'transfer_order' => 0,
        ];
    }
}
