<?php

namespace App\Models;

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

class ImportRequest extends Model
{
    use \Spatie\Activitylog\Traits\LogsActivity;

    protected $fillable = [
        'receiver_id', 'shipper_id', 'shipment_purpose', 'products_summary',
        'invoice_type', 'invoice_number', 'shipment_reference',
        'payment_by', 'duties_taxes_by', 'attachment', 'awb_no', 'is_documents',
        'courier_service', 'cost', 'actual_weight', 'remarks', 'special_instructions',
        'created_by', 'other_attachment', 'awb_updated_by', 'awb_updated_at'
    ];

    protected $casts = [
        'awb_updated_at' => 'datetime',
    ];

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

    public function items()
    {
        return $this->hasMany(ImportRequestItem::class);
    }

    public function packages()
    {
        return $this->hasMany(ImportRequestPackage::class);
    }

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

    public function shipper()
    {
        return $this->belongsTo(ImportPickupAddress::class, 'shipper_id');
    }

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

    public function user()
    {
        return $this->belongsTo(User::class);
    }

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