<?php

namespace App\Modules\HR\Assets\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use App\Modules\HR\Employees\Models\Employee;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Asset extends Model
{
    use BelongsToTenant;

    protected $table = 'hr_assets';

    protected $fillable = [
        'tenant_id', 'category', 'asset_code', 'name', 'serial_number', 'status',
        'purchase_date', 'warranty_until', 'location', 'notes', 'current_employee_id',
    ];

    protected function casts(): array
    {
        return ['purchase_date' => 'date', 'warranty_until' => 'date'];
    }

    public function currentEmployee(): BelongsTo
    {
        return $this->belongsTo(Employee::class, 'current_employee_id');
    }

    public function movements(): HasMany
    {
        return $this->hasMany(AssetMovement::class)->latest('created_at');
    }
}
