<?php

namespace App\Models\Warehouse\FixedAssets;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class FixedAssetCategory extends Model
{
    use HasFactory;

    protected $table = 'fixed_asset_categories';

    protected $fillable = [
        'category_code',
        'category_name',
        'depreciation_method',
        'default_useful_life_years',
        'default_salvage_value_pct',
        'status',
        'description',
    ];

    protected $casts = [
        'default_useful_life_years' => 'integer',
        'default_salvage_value_pct' => 'decimal:2',
    ];

    // Relationships

    public function assets()
    {
        return $this->hasMany(FixedAsset::class, 'category_id');
    }

    // Scopes

    public function scopeActive($query)
    {
        return $query->where('status', 'active');
    }
}
