<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SmartLeadershipReward extends Model
{
    protected $fillable = [
        'user_id',
        'level',
        'amount',
        'claimed_at',
    ];

    protected $casts = [
        'user_id' => 'integer',
        'level' => 'integer',
        'amount' => 'decimal:2',
        'claimed_at' => 'datetime',
    ];

    protected static function booted(): void
    {
        static::creating(function (self $reward): void {
            if (!$reward->claimed_at) {
                $reward->claimed_at = now();
            }
        });
    }

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