<?php

namespace App\Models;

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

class Order extends Model
{
    use HasFactory;

    protected $fillable = [
        'order_id',
        'mark_no',
        'origin',
        'destination',

        // totals only
        'ctn',
        'qty',
        'ttl_qty',
        'ttl_amount',
        'cbm',
        'ttl_cbm',
        'kg',
        'ttl_kg',

        'status'
    ];

    // One order has many items
    public function items()
    {
        return $this->hasMany(OrderItem::class);
    }

    // Link using mark_no (optional)
    public function markList()
    {
        return $this->hasOne(MarkList::class, 'mark_no', 'mark_no');
    }

    public function entries()
    {
        return $this->belongsToMany(Entry::class, 'entry_order', 'order_id', 'entry_id')
                    ->withTimestamps();
    }

    public function shipmentItems()
    {
        return $this->hasMany(\App\Models\ShipmentItem::class, 'order_id', 'id');
    }

    public function shipments()
    {
        return $this->belongsToMany(\App\Models\Shipment::class, 'shipment_items', 'order_id', 'shipment_id');
    }

        public function invoice()
    {
        return $this->hasOne(\App\Models\Invoice::class, 'order_id', 'id');
    }



}
