<?php

namespace App\Models;

use App\Enums\TransactionGateway;
use App\Enums\TransactionStatus;
use App\Models\Concerns\ScopedToOrganizer;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Transaction extends Model
{
    use ScopedToOrganizer;
    protected $fillable = [
        'order_id',
        'organizer_id',
        'gateway',
        'reference_id',
        'status',
        'amount',
        'currency',
        'error_code',
        'error_message',
        'payload',
    ];

    protected function casts(): array
    {
        return [
            'gateway' => TransactionGateway::class,
            'status' => TransactionStatus::class,
            'payload' => 'array',
        ];
    }

    public function order(): BelongsTo
    {
        return $this->belongsTo(Order::class);
    }

    public function organizer(): BelongsTo
    {
        return $this->belongsTo(Organizer::class);
    }
}
