<?php

namespace App\Http\Controllers\Api\V1\Admin\User\Concerns;

use App\Models\AdminUser;
use App\Lottery\ErrorCode;
use App\Support\ApiMessage;
use App\Support\ApiResponse;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;

trait EnsuresSuperAdminActor
{
    protected function ensureSuperAdmin(Request $request): ?JsonResponse
    {
        /** @var AdminUser $actor */
        $actor = $request->lotteryAdmin();
        if (! $actor->isSuperAdmin()) {
            return ApiMessage::errorResponse($request, 'admin.super_admin_only_for_roles', ErrorCode::AdminForbidden->value, null, 403);
        }

        return null;
    }
}
