<?php

namespace App\Models;

use App\Enums\ApprovalStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class TravelRequestApproval extends Model
{
    /** @use HasFactory<\Database\Factories\TravelRequestApprovalFactory> */
    use HasFactory;

    protected $fillable = [
        'travel_request_id',
        'approval_step_id',
        'approver_id',
        'status',
        'comments',
        'acted_at',
    ];

    protected function casts(): array
    {
        return [
            'status' => ApprovalStatus::class,
            'acted_at' => 'datetime',
        ];
    }

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

    public function step(): BelongsTo
    {
        return $this->belongsTo(ApprovalStep::class, 'approval_step_id');
    }

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