<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

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

    protected $casts = [
        'previous_expiry' => 'date',
        'new_expiry'      => 'date',
        'renewed_on'      => 'date',
        'cost'            => 'decimal:2',
    ];

    public const TYPES = ['passport', 'permit', 'fomema'];

    // Which staff expiry column each renewal type maintains.
    public const EXPIRY_COLUMN = [
        'passport' => 'passport_expiry',
        'permit'   => 'permit_expiry',
        'fomema'   => 'fomema_expiry',
    ];

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

    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
