<?php

namespace App\Models;

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

class FixedAssetMaintenance extends Model
{
    public const TYPES = [
        'preventive' => 'Preventive Maintenance',
        'repair' => 'Repair',
        'service' => 'Service',
        'inspection' => 'Inspection',
        'other' => 'Other',
    ];

    protected $fillable = [
        'maintenance_number','fixed_asset_id','branch_id','maintenance_date','maintenance_type','description','supplier','cost',
        'financial_account_id','reference','journal_number','next_due_date','notes','recorded_by',
    ];

    protected function casts(): array
    {
        return [
            'maintenance_date' => 'date',
            'next_due_date' => 'date',
            'cost' => 'decimal:2',
        ];
    }

    public function asset(): BelongsTo { return $this->belongsTo(FixedAsset::class, 'fixed_asset_id'); }
    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
    public function financialAccount(): BelongsTo { return $this->belongsTo(FinancialAccount::class); }
    public function recorder(): BelongsTo { return $this->belongsTo(User::class, 'recorded_by'); }
}
