<?php

declare(strict_types=1);

namespace App\Models\Auth;

use App\Contracts\Models\Nameable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Spatie\Permission\Models\Permission as BasePermission;

/**
 * @property Carbon $created_at
 * @property string $guard_name
 * @property int $id
 * @property string $name
 * @property Carbon $updated_at
 */
class Permission extends BasePermission implements Nameable
{
    final public const string TABLE = 'permissions';

    final public const string ATTRIBUTE_CREATED_AT = Model::CREATED_AT;
    final public const string ATTRIBUTE_GUARD_NAME = 'guard_name';
    final public const string ATTRIBUTE_ID = 'id';
    final public const string ATTRIBUTE_NAME = 'name';
    final public const string ATTRIBUTE_UPDATED_AT = Model::UPDATED_AT;

    final public const string RELATION_ROLES = 'roles';
    final public const string RELATION_USERS = 'users';

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            Permission::ATTRIBUTE_GUARD_NAME => 'string',
            Permission::ATTRIBUTE_NAME => 'string',
        ];
    }

    public function getName(): string
    {
        return $this->name;
    }
}
