<?php

namespace App\Models;

use App\Observers\TransactionObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Model;

#[ObservedBy(TransactionObserver::class)]
class Transaction extends Model
{
    protected $fillable = [
        'user_id',
        'amount',
        'type',
        'payment_method',
        'provider',
        'payment_reference',
        'payment_screenshot',
        'provider_order_number',
        'provider_transaction_id',
        'provider_payload',
        'approved_at',
        'rejected_at',
        'status',
        'raffle_id',
        'reseller_id',
        'quantity',
        'card_numbers',
    ];

    protected $casts = [
        'card_numbers' => 'array',
        'amount' => 'decimal:2',
        'provider_payload' => 'array',
        'approved_at' => 'datetime',
        'rejected_at' => 'datetime',
        'raffle_id' => 'integer',
        'reseller_id' => 'integer',
        'quantity' => 'integer',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function raffle()
    {
        return $this->belongsTo(Raffle::class);
    }

    public function reseller()
    {
        return $this->belongsTo(ResellerProfile::class, 'reseller_id');
    }

    public function commission()
    {
        return $this->hasOne(Commission::class);
    }
}
