<?php

namespace App\Models;

use App\Enums\TransactionMatterEnum;
use App\Enums\TransactionStatusEnum;
use App\Models\Scopes\TransactionScop;
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

#[ScopedBy([TransactionScop::class])]
class Transaction extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    public function casts(): array
    {
        return [
            'status' => TransactionStatusEnum::class,
            'matter' => TransactionMatterEnum::class,
        ];
    }

    public function getSearchAttribute()
    {
        return [
            'title',
            'track',
        ];
    }

    public function ref(): \Illuminate\Database\Eloquent\Relations\MorphTo
    {
        return $this->morphTo('ref', 'ref_type', 'ref_id', 'id');
    }

    public function holder(): \Illuminate\Database\Eloquent\Relations\MorphTo
    {
        return $this->morphTo('holder', 'holder_type', 'holder_id', 'id');
    }
}
