<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class StockAdjustment extends Model
{
    protected $fillable = [
        'adjustment_no', 'adjustment_date', 'warehouse_id', 'adjustment_type',
        'reason', 'notes', 'attachment', 'status', 'total_cost',
        'created_by', 'approved_by', 'approved_at',
    ];

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

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

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

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

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