<?php

namespace App\Domain\HR\Models;

use App\Domain\Shared\Traits\BelongsToAcademy;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Domain\Shared\Traits\ScopedThroughBranch;

class TrainerRateHistory extends Model
{
    use BelongsToAcademy, ScopedThroughBranch;

    /**
     * The parent whose branch this row inherits. A line item has no
     * branch of its own and must not grow one — a denormalised copy
     * here is a second source of truth that drifts the first time the
     * parent moves.
     */
    protected static string $branchScopeRelation = 'trainer';

    protected $fillable = [
        'academy_id',
        'trainer_id',
        'field',
        'old_value',
        'new_value',
        'effective_from',
        'changed_by',
        'notes',
    ];

    protected $casts = [
        'effective_from' => 'date',
    ];

    // --- Relationships ---

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

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