<?php

namespace App\Models;

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

class CostOfProduction extends Model
{
    use LogsActivity;

    protected $fillable = [
        'for_month',
        'cost_of_production',
        'calculation_data',
        'chart_of_account_id',
    ];

    protected $casts = [
        'for_month' => 'date',
        'cost_of_production' => 'decimal:2',
        'calculation_data' => 'array',
    ];

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

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->useLogName('cost_of_production')
            ->logFillable()
            ->logOnlyDirty()
            ->dontSubmitEmptyLogs();
    }
}
