<?php

namespace App\FiveM\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Bans live on the `fivem` connection (not the UCP's own `mysql` database)
 * so a Lua resource can check ban status with a single local oxmysql query
 * on player connect, without round-tripping to this app's API. The API in
 * routes/api.php (BanCheckController) exists for resources that would
 * rather call over HTTP than query the DB directly.
 */
class Ban extends Model
{
    protected $connection = 'fivem';

    protected $fillable = [
        'citizenid',
        'license',
        'reason',
        'banned_by',
        'expires_at',
    ];

    protected function casts(): array
    {
        return [
            'expires_at' => 'datetime',
        ];
    }

    public function getTable()
    {
        return config('fivem.ucp_tables.bans', 'ucp_bans');
    }

    public function isActive(): bool
    {
        return $this->expires_at === null || $this->expires_at->isFuture();
    }
}
