<?php

namespace Modules\Factor\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Str;
use Modules\Cheque\Entities\Cheque;
use Modules\Customer\Entities\Customer;
use Modules\Product\Entities\Product;

class Factor extends Model
{
    protected $guarded=['id'];

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            if (empty($model->uuid)) {
                $model->uuid = (string)Str::uuid();  // Generate UUID
            }
        });
    }

    public function products()
    {
        return $this->belongsToMany(Product::class)->withPivot('count', 'price', 'total');
    }

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }
    public function cheques()
    {
        return $this->hasMany(Cheque::class);
    }
}
