<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CashbackReward extends Model
{
    use HasFactory;

    public const STATUS_CREDITED = 'credited';
    public const STATUS_REVERSED = 'reversed';

    protected $guarded = [];

    protected $casts = [
        'base_amount' => 'decimal:2',
        'cashback_amount' => 'decimal:2',
        'meta_json' => 'array',
        'credited_at' => 'datetime',
        'reversed_at' => 'datetime',
    ];

    public function rule(): BelongsTo
    {
        return $this->belongsTo(CashbackRule::class, 'cashback_rule_id');
    }

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

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

