<?php

declare(strict_types=1);

namespace App\Models\Accounting;

use App\Models\Model;
use App\Models\User;

class AccountTransaction extends Model
{
    protected ?string $table = 'account_transactions';

    protected array $fillable = [
        'hashkey',
        'account_id',
        'item',
        'target_id',
        'amount',
        'flow',
        'notes',
        'transaction_date',
        'reference',
        'additional_details',
        'created_by',
        'updated_by',
    ];

    protected array $casts = [
        'additional_details' => 'json',
        'amount' => 'decimal:2',
        'transaction_date' => 'datetime',
    ];

    public function account()
    {
        return $this->belongsTo(Account::class, 'account_id');
    }

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updater()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
}
