<?php

declare(strict_types=1);

namespace App\Models;

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

class DberpSettlementEntry extends Model
{
    protected $table = 'dberp_settlement_entries';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'counterparty_type',
        'counterparty_id',
        'settlement_side',
        'change_type',
        'source_type',
        'source_id',
        'document_number',
        'change_amount',
        'balance_after',
        'business_time',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'counterparty_id' => 'integer',
            'source_id' => 'integer',
            'change_amount' => 'decimal:4',
            'balance_after' => 'decimal:4',
            'business_time' => 'datetime',
        ];
    }

    public function customer(): BelongsTo
    {
        return $this->belongsTo(DberpCustomer::class, 'counterparty_id');
    }

    public function supplier(): BelongsTo
    {
        return $this->belongsTo(DberpSupplier::class, 'counterparty_id');
    }
}