<?php

declare(strict_types=1);

namespace App\Models;

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

class DberpSettlementWriteOffLine extends Model
{
    protected $table = 'dberp_settlement_write_off_lines';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'write_off_id',
        'line_no',
        'settlement_side',
        'receipt_order_id',
        'payment_order_id',
        'receivable_record_id',
        'payable_record_id',
        'write_off_amount',
        'reversed_amount',
        'effective_amount',
        'line_status',
        'business_date',
        'reversed_at',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'write_off_id' => 'integer',
            'line_no' => 'integer',
            'receipt_order_id' => 'integer',
            'payment_order_id' => 'integer',
            'receivable_record_id' => 'integer',
            'payable_record_id' => 'integer',
            'write_off_amount' => 'decimal:4',
            'reversed_amount' => 'decimal:4',
            'effective_amount' => 'decimal:4',
            'business_date' => 'datetime',
            'reversed_at' => 'datetime',
        ];
    }

    public function writeOff(): BelongsTo
    {
        return $this->belongsTo(DberpSettlementWriteOff::class, 'write_off_id');
    }

    public function receiptOrder(): BelongsTo
    {
        return $this->belongsTo(DberpReceiptOrder::class, 'receipt_order_id');
    }

    public function paymentOrder(): BelongsTo
    {
        return $this->belongsTo(DberpPaymentOrder::class, 'payment_order_id');
    }

    public function receivableRecord(): BelongsTo
    {
        return $this->belongsTo(DberpReceivableRecord::class, 'receivable_record_id');
    }

    public function payableRecord(): BelongsTo
    {
        return $this->belongsTo(DberpPayableRecord::class, 'payable_record_id');
    }
}