<?php
// app/Models/ExpenseCategory.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;

class ExpenseCategory extends Model
{
    use LogsActivity;
    
    protected $table = 'expense_categories';
    
    protected $fillable = [
        'name',
        'description',
        'color',
        'is_active',
        'company_id',
    ];
    
    protected $casts = [
        'is_active' => 'boolean',
    ];
    
    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->useLogName('expense_category')
            ->logOnly(['name', 'description', 'color', 'is_active'])
            ->logOnlyDirty();
    }
    
    public function expenses(): HasMany
    {
        return $this->hasMany(Expense::class, 'category_id');
    }
    
    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class, 'company_id');
    }
}