<?php

declare(strict_types=1);

namespace App\Models;

use App\Enums\WorldRewardType;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class WorldRewardGrant extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'world_id',
        'artwork_id',
        'world_submission_id',
        'granted_by_user_id',
        'reward_type',
        'grant_source',
        'note',
        'granted_at',
    ];

    protected function casts(): array
    {
        return [
            'user_id' => 'integer',
            'world_id' => 'integer',
            'artwork_id' => 'integer',
            'world_submission_id' => 'integer',
            'granted_by_user_id' => 'integer',
            'reward_type' => WorldRewardType::class,
            'granted_at' => 'datetime',
        ];
    }

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

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

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

    public function worldSubmission(): BelongsTo
    {
        return $this->belongsTo(WorldSubmission::class, 'world_submission_id');
    }

    public function grantedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'granted_by_user_id');
    }
}