<?php

declare(strict_types=1);

namespace App\GraphQL\Schema\Types\Auth;

use App\GraphQL\Schema\Fields\Auth\Role\RoleColorField;
use App\GraphQL\Schema\Fields\Auth\Role\RoleDefaultField;
use App\GraphQL\Schema\Fields\Auth\Role\RoleNameField;
use App\GraphQL\Schema\Fields\Auth\Role\RolePriorityField;
use App\GraphQL\Schema\Fields\Base\CreatedAtField;
use App\GraphQL\Schema\Fields\Base\IdField;
use App\GraphQL\Schema\Fields\Base\UpdatedAtField;
use App\GraphQL\Schema\Fields\Field;
use App\GraphQL\Schema\Fields\Relations\BelongsToManyRelation;
use App\GraphQL\Schema\Types\EloquentType;
use App\Models\Auth\Role;

class RoleType extends EloquentType
{
    public function description(): string
    {
        return 'Represents an assignable label for users that provides a configured group of permissions.';
    }

    /**
     * The fields of the type.
     *
     * @return Field[]
     */
    public function fieldClasses(): array
    {
        return [
            new IdField(Role::ATTRIBUTE_ID, Role::class),
            new RoleNameField(),
            new RoleColorField(),
            new RoleDefaultField(),
            new RolePriorityField(),
            new CreatedAtField(),
            new UpdatedAtField(),

            new BelongsToManyRelation($this, new PermissionType(), Role::RELATION_PERMISSIONS),
        ];
    }
}
