<?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 SupplierBankAccount extends Model
{
    use BelongsToTenant;

    public $timestamps = true;

    public const UPDATED_AT = null;

    protected $fillable = [
        'uuid', 'supplier_id', 'bank_name', 'branch_name', 'account_number',
        'account_holder', '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);
    }
}
