<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class InventoryOpening extends Model
{
    protected $fillable = [
        'reference_no', 'opening_date', 'warehouse_id', 'financial_year_id',
        'notes', 'status', 'total_cost', 'created_by', 'approved_by', 'approved_at',
    ];

    protected $casts = [
        'opening_date' => 'date',
        'total_cost'   => 'decimal:2',
        'approved_at'  => 'datetime',
    ];

    public function warehouse()
    {
        return $this->belongsTo(Warehouse::class);
    }

    public function financialYear()
    {
        return $this->belongsTo(FinancialYear::class);
    }

    public function items()
    {
        return $this->hasMany(InventoryOpeningItem::class, 'opening_id');
    }

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

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