<?php

declare(strict_types=1);

namespace App\Models;

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

class DberpAdvanceAccount extends Model
{
    protected $table = 'dberp_advance_accounts';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'counterparty_type',
        'counterparty_id',
        'advance_direction',
        'currency_code',
        'total_amount',
        'used_amount',
        'occupied_amount',
        'available_amount',
        'account_status',
        'last_business_time',
        'source_system',
        'external_reference_id',
    ];

    protected function casts(): array
    {
        return [
            'counterparty_id' => 'integer',
            'total_amount' => 'decimal:4',
            'used_amount' => 'decimal:4',
            'occupied_amount' => 'decimal:4',
            'available_amount' => 'decimal:4',
            'last_business_time' => 'datetime',
        ];
    }

    public function flows(): HasMany
    {
        return $this->hasMany(DberpAdvanceAccountFlow::class, 'account_id');
    }
}