<?php

declare(strict_types=1);

namespace App\Models;

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

class DberpSettlementStatementItem extends Model
{
    protected $table = 'dberp_settlement_statement_items';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'statement_id',
        'line_no',
        'source_type',
        'source_id',
        'source_document_no',
        'summary',
        'business_time',
        'debit_amount',
        'credit_amount',
        'net_change_amount',
        'balance_after',
        'source_status',
        'snapshot_payload',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'statement_id' => 'integer',
            'line_no' => 'integer',
            'source_id' => 'integer',
            'business_time' => 'datetime',
            'debit_amount' => 'decimal:4',
            'credit_amount' => 'decimal:4',
            'net_change_amount' => 'decimal:4',
            'balance_after' => 'decimal:4',
            'snapshot_payload' => 'array',
        ];
    }

    public function statement(): BelongsTo
    {
        return $this->belongsTo(DberpSettlementStatement::class, 'statement_id');
    }
}