<?php

namespace App\Domain\HR\Models;

use App\Domain\HR\Enums\AdvanceStatus;
use App\Domain\Shared\Traits\BelongsToAcademy;
use App\Domain\Shared\Traits\HasUuid;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class TrainerAdvance extends Model
{
    use BelongsToAcademy, HasUuid, SoftDeletes;

    protected $fillable = [
        'academy_id',
        'trainer_id',
        'amount',
        'remaining_balance',
        'installment_amount',
        'installments_count',
        'installments_paid',
        'reason',
        'status',
        'issued_date',
        'expected_completion_date',
        'approved_by',
        'notes',
        'metadata',
        'created_by',
    ];

    protected $casts = [
        'status' => AdvanceStatus::class,
        'amount' => 'integer',
        'remaining_balance' => 'integer',
        'installment_amount' => 'integer',
        'installments_count' => 'integer',
        'installments_paid' => 'integer',
        'issued_date' => 'date',
        'expected_completion_date' => 'date',
        'metadata' => 'array',
    ];

    // --- Relationships ---

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

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

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