<?php

declare(strict_types=1);

namespace App\Models;

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

class DberpAdvanceAccountFlow extends Model
{
    protected $table = 'dberp_advance_account_flows';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'account_id',
        'flow_type',
        'receipt_order_id',
        'payment_order_id',
        'write_off_line_id',
        'change_amount',
        'balance_after',
        'business_date',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'account_id' => 'integer',
            'receipt_order_id' => 'integer',
            'payment_order_id' => 'integer',
            'write_off_line_id' => 'integer',
            'change_amount' => 'decimal:4',
            'balance_after' => 'decimal:4',
            'business_date' => 'datetime',
        ];
    }

    public function account(): BelongsTo
    {
        return $this->belongsTo(DberpAdvanceAccount::class, 'account_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 writeOffLine(): BelongsTo
    {
        return $this->belongsTo(DberpSettlementWriteOffLine::class, 'write_off_line_id');
    }
}