<?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 ManufacturingScrapBreakdown extends Model
{
    use LogsActivity;

    protected $fillable = [
        'manufacturing_run_id',
        'ingredient_account_id',
        'expected_qty',
        'actual_qty',
        'scrap_qty',
        'scrap_percentage',
        'unit',
        'notes',
    ];

    protected $casts = [
        'expected_qty' => 'decimal:4',
        'actual_qty' => 'decimal:4',
        'scrap_qty' => 'decimal:4',
        'scrap_percentage' => 'decimal:2',
    ];

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

    public function ingredientAccount(): BelongsTo
    {
        return $this->belongsTo(Account::class, 'ingredient_account_id');
    }

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