<?php

namespace App\Domain\Financial\Models;

use App\Domain\Shared\Traits\Auditable;
use App\Domain\Shared\Traits\BelongsToAcademy;
use App\Domain\Shared\Traits\HasUuid;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class Wallet extends Model
{
    use HasUuid, BelongsToAcademy, Auditable;

    protected $fillable = [
        'academy_id',
        'owner_type',
        'owner_id',
        'balance',
        'currency',
        'is_active',
    ];

    protected function casts(): array
    {
        return [
            'balance' => 'integer',
            'is_active' => 'boolean',
        ];
    }

    public function owner(): MorphTo
    {
        return $this->morphTo();
    }

    public function walletTransactions(): HasMany
    {
        return $this->hasMany(WalletTransaction::class);
    }

    public function formattedBalance(): string
    {
        return number_format($this->balance / 100, 2) . ' ' . $this->currency;
    }

    public function isFinancialAudit(): bool
    {
        return true;
    }
}
