<?php

namespace App\Modules\Accounting\Models;

use App\Modules\Tenant\Models\Company;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class AccountTransaction extends Model
{
    use HasFactory;

    protected $fillable = [
        'company_id',
        'financial_account_id',
        'source_type',
        'source_id',
        'transaction_date',
        'type',
        'direction',
        'amount',
        'description',
        'reference',
        'notes',
    ];

    protected $casts = [
        'transaction_date' => 'date',
        'amount' => 'decimal:2',
    ];

    /**
     * @return BelongsTo<Company, AccountTransaction>
     */
    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class);
    }

    /**
     * @return BelongsTo<FinancialAccount, AccountTransaction>
     */
    public function financialAccount(): BelongsTo
    {
        return $this->belongsTo(FinancialAccount::class);
    }

    /**
     * @return MorphTo<Model, AccountTransaction>
     */
    public function source(): MorphTo
    {
        return $this->morphTo();
    }
}
