<?php

namespace App\Modules\Inventory\Models;

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

class GoodsReceipt extends Model
{
    use HasFactory, SoftDeletes;
    use \Spatie\Activitylog\Traits\LogsActivity;

    protected $fillable = [
        'code',
        'type',
        'warehouse_id',
        'purchase_order_id',
        'vendor_id',
        'received_date',
        'status',
        'remarks',
        'user_id',
    ];

    protected $casts = [
        'received_date' => 'date:Y-m-d',
    ];

    public function getActivitylogOptions(): \Spatie\Activitylog\LogOptions
    {
        return \Spatie\Activitylog\LogOptions::defaults()
            ->logAll()
            ->logOnlyDirty()
            ->dontSubmitEmptyLogs();
    }

    public function items()
    {
        return $this->hasMany(GoodsReceiptItem::class);
    }
    
    // Strict Mode: relationships to Warehouse is allowed (same module).
    public function warehouse()
    {
        return $this->belongsTo(Warehouse::class);
    }
    
    // Strict Mode: cross-module relationship to Vendor/User/PurchaseOrder is restricted.
    // They are accessed via IDs or Services.
}
