<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class GameRank extends Model
{
    protected $fillable = [
        'game_id',
        'name',
        'color',
        'sort_order',
        'min_value',
    ];

    protected function casts(): array
    {
        return [
            'sort_order' => 'integer',
            'min_value' => 'integer',
        ];
    }

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

    public function currentRankProfiles(): HasMany
    {
        return $this->hasMany(PlayerGameProfile::class, 'current_rank_id');
    }

    public function highestRankProfiles(): HasMany
    {
        return $this->hasMany(PlayerGameProfile::class, 'highest_rank_id');
    }

    public function records(): HasMany
    {
        return $this->hasMany(PlayerRecord::class, 'rank_id');
    }
}
