<?php

namespace App\Modules\CardPinOrder\Models;

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

/**
 * @param  int  $id
 *
 * @property string $unique_id
 * @property int $user_id
 * @property int $card_type_id
 * @property string $card_number
 * @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 $passport_one
 * @property string $passport_two
 * @property string $passport_three
 * @property string $passport_four
 * @property string $status
 * @property null|string $notes
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 */
class CardPinOrder extends Model implements BelongsToBranch, HasStatus
{
    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'born_at' => 'date',
    ];

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

    /**
     * Card type
     *
     * @return BelongsTo<CardType, $this>
     */
    public function cardType(): BelongsTo
    {
        return $this->belongsTo(CardType::class, 'card_type_id');
    }

    /**
     * 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());
    }
}
