<?php

namespace App\Models\Purchasing;

use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;

class SupplierContact extends Model
{
    use BelongsToTenant;

    public $timestamps = true;

    public const UPDATED_AT = null;

    protected $fillable = ['uuid', 'supplier_id', 'name', 'designation', 'phone', 'email', 'is_primary', 'created_by'];

    protected function casts(): array
    {
        return ['is_primary' => 'boolean'];
    }

    protected static function booted(): void
    {
        static::creating(function (self $model): void {
            if (! $model->uuid) {
                $model->uuid = (string) Str::ulid();
            }
        });
    }

    public function supplier(): BelongsTo
    {
        return $this->belongsTo(Supplier::class);
    }
}
