<?php

namespace App\Modules\LoanPaidOffLetter\Models;

use App\Models\User;
use App\Modules\Branch\Interfaces\BelongsToBranch;
use App\Modules\Branch\Models\Branch;
use App\Modules\LoanOrder\Repositories\LoanOrderRepository;
use App\Modules\OrderStatus\Interfaces\HasStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * @property int $id
 * @property string $unique_id
 * @property string $region
 * @property int $branch_id
 * @property string $customer_name
 * @property string $customer_surname
 * @property string $customer_patronic_name
 * @property \Illuminate\Support\Carbon $born_at
 * @property string $phone
 * @property string $passport_serie
 * @property string $passport_id
 * @property string $status
 * @property string $notes
 * @property int $user_id
 * @property string $loan_contract_number
 * @property string $loan_contract_date
 * @property string $loan_amount
 * @property string $loan_reason
 * @property null|string $loan_file
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon $updated_at
 */
class LoanPaidOffLetter extends Model implements BelongsToBranch, HasStatus
{
    protected $table = 'loan_paid_off_letters';

    protected $casts = [
        'born_at' => 'date',
        'loan_contract_date' => 'date',
    ];

    /**
     * User
     *
     * @return BelongsTo<User, $this>
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Branch
     *
     * @return BelongsTo<Branch, $this>
     */
    public function branch(): BelongsTo
    {
        return $this->belongsTo(Branch::class);
    }

    /**
     * "boot" method for model
     */
    protected static function boot(): void
    {
        parent::boot();

        static::creating(LoanOrderRepository::creating());
        static::created(LoanOrderRepository::created());
    }
}
