<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class InventoryOpeningItem extends Model
{
    protected $fillable = [
        'opening_id', 'product_id', 'unit_id',
        'qty', 'base_qty', 'unit_cost', 'total_cost',
        'batch_number', 'expiry_date',
    ];

    protected $casts = [
        'qty'         => 'decimal:4',
        'base_qty'    => 'decimal:4',
        'unit_cost'   => 'decimal:4',
        'total_cost'  => 'decimal:4',
        'expiry_date' => 'date',
    ];

    public function opening()
    {
        return $this->belongsTo(InventoryOpening::class);
    }

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function unit()
    {
        return $this->belongsTo(Unit::class);
    }
}
