<?php

namespace App\Models;

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

class CourierSettlement extends Model
{
    use HasFactory;

    protected $guarded = [];

    protected $casts = [
        'settlement_date' => 'date',
        'total_cod_amount' => 'float',
        'delivery_charge_deduction' => 'float',
        'cod_charge_deduction' => 'float',
        'return_charge_deduction' => 'float',
        'adjustment_amount' => 'float',
        'net_received_amount' => 'float',
        'payload' => 'array',
        'reversed_at' => 'datetime',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    public function courier()
    {
        return $this->belongsTo(Courier::class);
    }

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

    public function ledgerEntries()
    {
        return $this->hasMany(CourierLedgerEntry::class);
    }

    public function createdByAdmin()
    {
        return $this->belongsTo(Admin::class, 'created_by_admin_id');
    }
}
