import UserMiddleware from "./UserAuthorization";
import JSONWebToken from "../Utils/JsonWebToken";
import Response from "../Utils/Response";
import NotAuthorizedException from "../../Types/Exception/NotAuthorizedException";
export default class MasterAdminAuthorization {
    static async isAuthorizedMasterAdminMiddleware(req, res, next) {
        try {
            const accessToken = UserMiddleware.getAccessTokenFromExpressRequest(req);
            if (!accessToken) {
                Response.sendErrorResponse(req, res, new NotAuthorizedException("Unauthorized: Access token is required."));
                return;
            }
            const authData = JSONWebToken.decode(accessToken);
            if (!authData.isMasterAdmin) {
                Response.sendErrorResponse(req, res, new NotAuthorizedException("Unauthorized: Only master admins can perform this action."));
                return;
            }
            next();
        }
        catch (_a) {
            Response.sendErrorResponse(req, res, new NotAuthorizedException("Unauthorized: Invalid or expired access token."));
        }
    }
}
//# sourceMappingURL=MasterAdminAuthorization.js.map