<?php

namespace App\Models;

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

class ForecastDetail extends Model
{
    use HasFactory;

    protected $table = 't_forecast_details';

    protected $fillable = [
        'forecast_header_id',
        'store_id',
        'raw_material_id',
        'forecast_date',
        'forecast_qty',
        'notes',
        'delete_flag',
        'created_by',
        'updated_by',
    ];

    protected $casts = [
        'forecast_date' => 'date',
        'forecast_qty' => 'decimal:2',
        'delete_flag' => 'boolean',
    ];

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function modificator()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }

    public function header()
    {
        return $this->belongsTo(Forecast::class, 'forecast_header_id');
    }

    public function store()
    {
        return $this->belongsTo(Store::class, 'store_id');
    }

    public function rawMaterial()
    {
        return $this->belongsTo(RawMaterial::class, 'raw_material_id');
    }

    // Get effective quantity (just forecast_qty since no adjustment needed)
    public function getEffectiveQtyAttribute()
    {
        return $this->forecast_qty;
    }
}
