<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Invoice extends Model
{
    protected $fillable = [
        'consignment_id',
        'invoice_number',
        'amount_usd',
        'amount_kes',
        'extra_charge_usd',
        'amount_paid_kes',
        'outstanding_kes',
        'payment_status',
        'due_date',
        'created_by',
    ];

    protected $casts = [
        'amount_usd'       => 'decimal:2',
        'amount_kes'       => 'decimal:2',
        'extra_charge_usd' => 'decimal:2',
        'amount_paid_kes'  => 'decimal:2',
        'outstanding_kes'  => 'decimal:2',
        'due_date'         => 'date',
    ];

    public function consignment(): BelongsTo
    {
        return $this->belongsTo(Consignment::class);
    }

    public function payments(): HasMany
    {
        return $this->hasMany(Payment::class);
    }

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