import { HttpStatusCode } from "./http-status.js";
import { ProblemDetails, ProblemDetailsFactory } from "./interfaces.js";
import { getSourceControlProviderLabel } from "./utils.js";

// Generic
const zuploGithubAppInstallationUrl =
  "https://github.com/apps/zuplo/installations/new";
export const INTERNAL_SERVER_ERROR: ProblemDetails = {
  type: "https://zup.fail/http-status/500",
  title: "Internal Server Error",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
};

export const BAD_REQUEST: ProblemDetails = {
  type: "https://zup.fail/http-status/400",
  title: "Bad Request",
  status: HttpStatusCode.BAD_REQUEST,
};

export const CONFLICT: ProblemDetails = {
  type: "https://zup.fail/http-status/409",
  title: "Conflict",
  status: HttpStatusCode.CONFLICT,
};

export const NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/http-status/404",
  title: "Not Found",
  status: HttpStatusCode.NOT_FOUND,
};

export const METHOD_NOT_ALLOWED: ProblemDetails = {
  type: "https://zup.fail/http-status/405",
  title: "Method Not Allowed",
  status: HttpStatusCode.METHOD_NOT_ALLOWED,
};

export const UNAUTHORIZED: ProblemDetails = {
  type: "https://zup.fail/http-status/401",
  title: "Unauthorized",
  status: HttpStatusCode.UNAUTHORIZED,
};

export const FORBIDDEN: ProblemDetails = {
  type: "https://zup.fail/http-status/403",
  title: "Forbidden",
  status: HttpStatusCode.FORBIDDEN,
};

// Custom

export const CLIENT_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/client-not-found",
  title: "Client not found",
  status: HttpStatusCode.NOT_FOUND,
};

export const USER_ALREADY_EXISTS: ProblemDetails = {
  type: "https://zup.fail/user-already-exists",
  title: "User already exists",
  status: HttpStatusCode.CONFLICT,
};

export const USER_DETAILS_CANNOT_BE_FOUND: ProblemDetails = {
  type: "https://zup.fail/user-details-cannot-be-found",
  title: "User cannot be found",
  status: HttpStatusCode.NOT_FOUND,
};

export const USER_HAS_NO_ACCESS_TO_ACCOUNT: ProblemDetails = {
  type: "https://zup.fail/user-has-no-access-to-account",
  title: "Forbidden",
  detail: "You are not authorized to access the account resource.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_TO_APIKEY_BUCKET: ProblemDetails = {
  type: "https://zup.fail/no-access-to-apikey-bucket",
  title: "Forbidden",
  detail: "You are not authorized to access this account's api key bucket.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_TO_PROJECT_APIKEY_BUCKET: ProblemDetails = {
  type: "https://zup.fail/no-access-to-project-apikey-bucket",
  title: "Forbidden",
  detail:
    "You must be a project member to access this api key bucket. Please contact your project administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_READ_APIKEYS: ProblemDetails = {
  type: "https://zup.fail/no-access-read-apikeys",
  title: "Forbidden",
  detail:
    "Reading this account's api keys requires account admin privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_CREATE_APIKEYS: ProblemDetails = {
  type: "https://zup.fail/no-access-create-apikeys",
  title: "Forbidden",
  detail:
    "Creating an account's api key requires account admin privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_CREATE_PRODUCTION_APIKEY_CONSUMERS: ProblemDetails = {
  type: "https://zup.fail/no-access-create-production-apikey-consumers",
  title: "Forbidden",
  detail:
    "Creating an api key consumer requires account admin privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_CREATE_APIKEY_CONSUMERS: ProblemDetails = {
  type: "https://zup.fail/no-access-create-apikey-consumers",
  title: "Forbidden",
  detail:
    "Creating an api key consumer requires account admin or developer privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_EDIT_PRODUCTION_APIKEY_CONSUMERS: ProblemDetails = {
  type: "https://zup.fail/no-access-edit-production-apikey-consumers",
  title: "Forbidden",
  detail:
    "Updating an api key consumer requires account admin privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_EDIT_APIKEY_CONSUMERS: ProblemDetails = {
  type: "https://zup.fail/no-access-edit-apikey-consumers",
  title: "Forbidden",
  detail:
    "Updating an api key consumer requires account admin or developer privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_EDIT_APIKEY_BUCKET: ProblemDetails = {
  type: "https://zup.fail/no-access-edit-apikey-bucket",
  title: "Forbidden",
  detail:
    "Updating an api key bucket requires account admin or developer privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_EDIT_METERING_BUCKET: ProblemDetails = {
  type: "https://zup.fail/no-access-edit-metering-bucket",
  title: "Forbidden",
  detail:
    "Updating a metering bucket requires account admin or developer privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_READ_BILLING: ProblemDetails = {
  type: "https://zup.fail/no-access-read-billing",
  title: "Forbidden",
  detail:
    "Accessing this account's billing information requires account admin privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_UPDATE_PLAN: ProblemDetails = {
  type: "https://zup.fail/no-access-update-billing",
  title: "Forbidden",
  detail:
    "Updating this account's plan requires account admin privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};
export const NO_ACCESS_TO_CREATE_DEPLOYMENT: ProblemDetails = {
  type: "https://zup.fail/no-access-to-create-deployment",
  title: "Forbidden",
  detail: "You are not authorized to create a new deployment for this project.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_TO_UPDATE_DEPLOYMENT: ProblemDetails = {
  type: "https://zup.fail/no-access-to-update-deployment",
  title: "Forbidden",
  detail: "You are not authorized to update this project's deployment.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_PROJECT_SOURCE_CONTROL: ProblemDetails = {
  type: "https://zup.fail/no-access-project-source-control",
  title: "Forbidden",
  detail:
    "You are not authorized to access the project source control settings.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_PROJECT_SOURCE_CONTROL_UPDATE: ProblemDetails = {
  type: "https://zup.fail/no-access-project-source-control-update",
  title: "Forbidden",
  detail:
    "Updating project source control settings requires project admin privileges. Please contact your project administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_CREATE_PROJECT: ProblemDetails = {
  type: "https://zup.fail/no-access-create-project",
  title: "Forbidden",
  detail:
    "Creating a project requires account admin privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};
export const NO_ACCESS_DELETE_PROJECT: ProblemDetails = {
  type: "https://zup.fail/no-access-delete-project",
  title: "Forbidden",
  detail:
    "Deleting a project requires account admin privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const USER_HAS_NO_PROJECT_BUILD_VIEWER_ACCESS: ProblemDetails = {
  type: "https://zup.fail/user-has-no-project-build-viewer-access",
  title: "Forbidden",
  detail: "You are not authorized to access the view project build resources.",
  status: HttpStatusCode.FORBIDDEN,
};

export const USER_REMOVE_NOT_MEMBER_ACCOUNT: ProblemDetails = {
  type: "https://zup.fail/removed-user-not-account-member",
  title: "The user being removed is not a member of the account",
  status: HttpStatusCode.BAD_REQUEST,
};

export const USER_IS_NOT_SERVICE_ACCOUNT: ProblemDetails = {
  type: "https://zup.fail/user-not-service-account",
  title: "User is not a service account",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/account-not-found",
  title: "Account not found",
  status: HttpStatusCode.NOT_FOUND,
};

export const ACCOUNT_ALREADY_EXISTS: ProblemDetails = {
  type: "https://zup.fail/account-already-exists",
  title: "Account already exists",
  status: HttpStatusCode.CONFLICT,
};

export const ACCOUNT_NAME_USES_RESERVED_KEYWORD: ProblemDetails = {
  type: "https://zup.fail/account-name-reserved-keyword",
  title: "The account name can not use reserved keyword 'zuplo'",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_NAME_STARTS_WITH_RESERVED_KEYWORD: ProblemDetails = {
  type: "https://zup.fail/account-use-reserved-keyword",
  title: "The account name can not start with a reserved keyword",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_NAME_LENGTH_LIMIT_REACHED = (
  lengthLimit: number
): ProblemDetails => ({
  type: "https://zup.fail/account-name-length-limit",
  title: `The account name exceeds the ${lengthLimit} character limit`,
  status: HttpStatusCode.BAD_REQUEST,
});

export const ACCOUNT_LABEL_LENGTH_LIMIT_REACHED = (
  lengthLimit: number
): ProblemDetails => ({
  type: "https://zup.fail/account-label-length-limit",
  title: `The account label exceeds the ${lengthLimit} character limit`,
  status: HttpStatusCode.BAD_REQUEST,
});

export const INVALID_ACCOUNT_NAME: ProblemDetails = {
  type: "https://zup.fail/invalid-account-name",
  title:
    "The account name can only contain lower-cased characters, numbers, dashes and underscores",
  status: HttpStatusCode.BAD_REQUEST,
};

export const INVALID_ACCOUNT_LABEL: ProblemDetails = {
  type: "https://zup.fail/invalid-account-label",
  title:
    "The account label can only contain alpha-numeric characters, spaces, dashes and underscores",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_NAME_ALREADY_IN_USE: ProblemDetails = {
  type: "https://zup.fail/account-name-in-use",
  title:
    "The account name is already taken. Please try again using a different name.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const INVALID_ACCOUNT_NAME_ENDING: ProblemDetails = {
  type: "https://zup.fail/invalid-account-name-ending",
  title: "The account name can not end with a dash or underscore character",
  status: HttpStatusCode.BAD_REQUEST,
};

export const INVALID_ACCOUNT_LABEL_ENDING: ProblemDetails = {
  type: "https://zup.fail/invalid-account-label-ending",
  title: "The account label can not end with a dash or underscore character",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_DOES_NOT_EXISTS: ProblemDetails = {
  type: "https://zup.fail/account-does-not-exists",
  title: "Not Found",
  detail: "The account does not exist.",
  status: HttpStatusCode.NOT_FOUND,
};

export const ACCOUNT_INFO_MISSING: ProblemDetails = {
  type: "https://zup.fail/account-info-missing",
  title: "Account information is required",
  status: HttpStatusCode.NOT_FOUND,
};

export const ACCOUNT_UPDATE_INFO_MISSING: ProblemDetails = {
  type: "https://zup.fail/account-update-info-missing",
  title: "Account information is insufficient for this operation.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_MEMBER_ALREADY_EXISTS: ProblemDetails = {
  type: "https://zup.fail/account-member-already-exists",
  title: "Account member already exists",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_MEMBER_INFO_MISSING: ProblemDetails = {
  type: "https://zup.fail/account-member-info-missing",
  title: "Account member information is required",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_MEMBER_DOES_NOT_EXIST: ProblemDetails = {
  type: "https://zup.fail/account-member-does-not-exists",
  title: "Account member information cannot be found",
  status: HttpStatusCode.NOT_FOUND,
};

export const ACCOUNT_MEMBER_INVITE_DOES_NOT_EXIST: ProblemDetails = {
  type: "https://zup.fail/account-member-invite-does-not-exist",
  title: "Account member invite cannot be found",
  status: HttpStatusCode.NOT_FOUND,
};

export const ACCOUNT_MEMBER_INVITE_INVALID: ProblemDetails = {
  type: "https://zup.fail/account-member-invite-invalid",
  title: "Account member invite is invalid",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_MEMBER_INVITE_FAILED_TO_SEND: ProblemDetails = {
  type: "https://zup.fail/account-member-invite-failed-send",
  title:
    "We were not able to send the account member invite. Please try again or contact support.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const CANNOT_INVITE_EXISTING_ACCOUNT_MEMBER: ProblemDetails = {
  type: "https://zup.fail/account-member-cannot-be-invited",
  title: "The user is already part of the account.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const EXISTING_PENDING_ACCOUNT_MEMBER_INVITE: ProblemDetails = {
  type: "https://zup.fail/existing-pending-account-member-invites",
  title: "The user has a pending invitation to this account.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const MULTIPLE_ACCOUNT_MEMBERS_NOT_ALLOWED: ProblemDetails = {
  type: "https://zup.fail/no-multi-account-members",
  title: "Account is not configured for multiple members",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_MEMBERS_ALLOWED_LIMIT_REACHED: ProblemDetails = {
  type: "https://zup.fail/account-members-limit-reached",
  title:
    "This account has reached the limit of users allowed by its current billing plan.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const PROJECT_SHARING_DISABLED_ON_ACCOUNT: ProblemDetails = {
  type: "https://zup.fail/project-sharing-disabled-on-account",
  title: "Project sharing is not enabled on account",
  status: HttpStatusCode.FORBIDDEN,
};

export const PROJECT_NOT_FOUND_FOR_SOURCE_REPO: ProblemDetails = {
  type: "https://zup.fail/project-not-found-for-source-repo",
  title: "Project not found for provided repository",
  status: HttpStatusCode.NOT_FOUND,
};

export const PROJECT_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/project-not-found",
  title: "Project not found",
  status: HttpStatusCode.NOT_FOUND,
};

export const PROJECT_CANNOT_BE_DELETED_PROTECTED_DEPLOYMENTS_EXISTS: ProblemDetails =
  {
    type: "https://zup.fail/project-cannot-be-deleted-protected-deployments-exists",
    title: "Project cannot be deleted because it has protected deployments",
    detail:
      "Project has protected deployments. Make sure to remove the use of custom domains before trying to delete the project.",
    status: HttpStatusCode.FORBIDDEN,
  };

export const INCORRECT_PROJECT_TEMPLATE: ProblemDetails = {
  type: "https://zup.fail/incorrect-project-template",
  title: "Incorrect project template name",
  status: HttpStatusCode.BAD_REQUEST,
};

export const INVALID_TEMPLATE_REPOSITORY: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/user-no-access-github-app-repo",
  title: `The repository '${repositoryUrl} is not a valid Zuplo template repository`,
  status: HttpStatusCode.FORBIDDEN,
});

export const PROJECT_MEMBER_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/project-member-not-found",
  title: "Project Member not found",
  status: HttpStatusCode.NOT_FOUND,
};

export const PROJECT_MEMBER_ALREADY_EXISTS: ProblemDetails = {
  type: "https://zup.fail/project-member-already-exists",
  title: "Project Member already exists",
  status: HttpStatusCode.BAD_REQUEST,
};

export const CAN_NOT_DELETE_YOUR_OWN_PROJECT_MEMBERS: ProblemDetails = {
  type: "https://zup.fail/cannt-delete-your-own-project-member",
  title: "Can not delete your own Project Member record",
  status: HttpStatusCode.BAD_REQUEST,
};

export const PROJECT_MUST_HAVE_ONE_MEMBER: ProblemDetails = {
  type: "https://zup.fail/project-must-have-one-member",
  title: "Project must have at least one member",
  status: HttpStatusCode.BAD_REQUEST,
};

export const SHARED_PROJECT_PREVIOUSLY_INITIALIZED: ProblemDetails = {
  type: "https://zup.fail/project-previously-initialized",
  title: "Project was previously initialized",
  status: HttpStatusCode.BAD_REQUEST,
};

export const INVALID_SOURCE_REPO_URL: ProblemDetails = {
  type: "https://zup.fail/invalid-source-repo-url",
  title:
    "Project is not connected to source control, a sourceRepoUrl property must be specified and valid",
  status: HttpStatusCode.BAD_REQUEST,
};

export const DEPLOYMENT_NO_ACCESS: ProblemDetails = {
  type: "https://zup.fail/deployment-no-access",
  title: "User does not have access to deployment",
  status: HttpStatusCode.FORBIDDEN,
};

export const DEPLOYMENT_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/deployment-not-found",
  title: "Deployment was not found",
  status: HttpStatusCode.NOT_FOUND,
};

export const DEPLOYMENT_NOT_FOUND_WORKING_COPY: ProblemDetails = {
  type: "https://zup.fail/deployment-not-found-working-copy",
  title: "Working copy deployment was not found",
  detail: "This operation is only available for working copy deployments",
  status: HttpStatusCode.BAD_REQUEST,
};

export const DEPLOYMENT_FILE_DOES_NOT_EXISTS: ProblemDetails = {
  type: "https://zup.fail/deployment-file-does-not-exists",
  title: "Files were not found",
  status: HttpStatusCode.NOT_FOUND,
};

export const INVALID_WORKING_COPY_DEPLOYMENT: ProblemDetails = {
  type: "https://zup.fail/invalid-working-copy-deployment",
  title:
    "The working copy configuration provided is invalid. Please try again or contact support if issue persists.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const DEPLOYMENT_DIR_DOES_NOT_EXISTS: ProblemDetails = {
  type: "https://zup.fail/deployment-dir-does-not-exists",
  title: "NOT FOUND",
  detail: "Deployment directory was not found",
  status: HttpStatusCode.NOT_FOUND,
};

export const DEPLOYMENT_REQUEST_IS_NOT_MULTI_PART: ProblemDetails = {
  type: "https://zup.fail/deployment-request-is-not-multi-part",
  title: "Request is not multipart.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const DEPLOYMENT_INVALID_MULTI_PART: ProblemDetails = {
  type: "https://zup.fail/deployment-invalid-multi-part",
  title: "Invalid request format. Must be multi-part file upload.",
  status: HttpStatusCode.BAD_REQUEST,
};
export const DEPLOYMENT_CANNOT_DELETE_INSTANCE: ProblemDetails = {
  type: "https://zup.fail/deployment-cannot-delete-instance",
  title:
    "Cannot delete instance of the deployment. Invalid account or project.",
  status: HttpStatusCode.NOT_FOUND,
};

export const DEPLOYMENT_DELETE_ERROR: ProblemDetails = {
  type: "https://zup.fail/deployment-delete-error",
  title: "Error deleting deployment instance.",
  status: HttpStatusCode.NOT_FOUND,
};

export const DEPLOYMENT_INVALID_ENVIRONMENT_TO_DELETE: ProblemDetails = {
  type: "https://zup.fail/deployment-invalid-environment-to-delete",
  title: "Invalid environment to delete deployment",
  status: HttpStatusCode.BAD_REQUEST,
};

export const DEPLOYMENT_IS_PROTECTED_CANNOT_BE_DELETED: ProblemDetails = {
  type: "https://zup.fail/deployment-is-protected-cannot-be-deleted",
  title: "Deployment is protected and cannot be deleted",
  status: HttpStatusCode.FORBIDDEN,
};

export const DEPLOYMENT_CANNOT_BE_REDEPLOYED_DUE_TO_ACCOUNT: ProblemDetails = {
  type: "https://zup.fail/deployment-log-not-found",
  title: "Deployment cannot be redeployed due to invalid account",
  status: HttpStatusCode.NOT_FOUND,
};

export const DEPLOYMENT_CANNOT_BE_REDEPLOYED_DUE_TO_PROJECT: ProblemDetails = {
  type: "https://zup.fail/deployment-log-not-found",
  title: "Deployment cannot be redeployed due to invalid project name",
  status: HttpStatusCode.NOT_FOUND,
};

export const DEPLOYMENT_CANNOT_BE_REDEPLOYED_DUE_TO_USER_SUB: ProblemDetails = {
  type: "https://zup.fail/deployment-log-not-found",
  title: "Deployment cannot be redeployed due to invalid user sub",
  status: HttpStatusCode.NOT_FOUND,
};

export const DEPLOYMENT_CANNOT_BE_DELETED_DUE_WORKING_COPY: ProblemDetails = {
  type: "https://zup.fail/deployment-cannot-be-deleted",
  title: "Deployment cannot be deleted since is a working copy",
  status: HttpStatusCode.FORBIDDEN,
};

export const DEPLOYMENT_LOG_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/deployment-log-not-found",
  title: "DeploymentLog was not found",
  status: HttpStatusCode.NOT_FOUND,
};

export const DEPLOYMENT_NOT_WORKING_COPY: ProblemDetails = {
  type: "https://zup.fail/deployment-not-working-copy",
  title: `Deployment is not working copy.`,
  status: HttpStatusCode.BAD_REQUEST,
};

export const WORKING_COPY_NOT_ALLOWED_MANAGED_DEDICATED: ProblemDetails = {
  type: "https://zup.fail/working-copy-not-allowed-managed-dedicated",
  title:
    "Working-copy deployments are not allowed for managed-dedicated projects",
  status: HttpStatusCode.BAD_REQUEST,
  detail: "Use an external IDE to edit code on a managed-dedicated project.",
};

export const DEPLOYMENT_INCORRECT_STATUS_PAUSE: ProblemDetails = {
  type: "https://zup.fail/deployment-incorrect-status-pause",
  title: "Deployment is not in a state to be paused.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const DEPLOYMENT_INCORRECT_STATUS_UNPAUSE: ProblemDetails = {
  type: "https://zup.fail/deployment-incorrect-status-unpause",
  title: "Deployment is not in a state to be unpaused.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const SERVICE_CONFIGURATION_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/service-config-not-found",
  title: "Service configuration not found.",
  status: HttpStatusCode.NOT_FOUND,
};

export const WORKING_COPY_SERVICE_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/service-config-not-found",
  title: "Working Copy service not found.",
  status: HttpStatusCode.NOT_FOUND,
};

export const WORKING_COPY_SERVICE_NOT_DELETED: ProblemDetails = {
  type: "https://zup.fail/working-copy-service-not-deleted",
  title: "Working Copy service failed to be deleted.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const WORKING_COPY_SERVICE_NOT_CREATED: ProblemDetails = {
  type: "https://zup.fail/working-copy-service-not-created",
  title: "Working Copy service failed to be created.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const SERVICE_CONFIGURATION_FAILED_DECRYPTION: ProblemDetails = {
  type: "https://zup.fail/service-config-not-decrypted",
  title: "Service configuration failed to decrypt.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const PROJECT_ALREADY_EXISTS: ProblemDetails = {
  type: "https://zup.fail/project-already-exists",
  title: "Project already exists.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const PROJECT_NO_MEMBERS: ProblemDetails = {
  type: "https://zup.fail/project-no-members",
  title: "Cannot find project members.",
  status: HttpStatusCode.NOT_FOUND,
};

export const RUNTIME_FLAG_ALREADY_EXISTS: ProblemDetails = {
  type: "https://zup.fail/runtime-flag-already-exists",
  title: "RuntimeFlag already exists.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const RUNTIME_FLAG_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/runtime-flag-not-found",
  title: "RuntimeFlag was not found.",
  status: HttpStatusCode.NOT_FOUND,
};

export const RUNTIME_FLAG_KEY_NOT_VALID: ProblemDetails = {
  type: "https://zup.fail/runtime-flag-key-not-valid",
  title: "RuntimeFlag key must be snake case",
  status: HttpStatusCode.BAD_REQUEST,
};

export const USER_HAS_NO_ACCESS_TO_PROJECT: ProblemDetails = {
  type: "https://zup.fail/user-has-no-access-to-project",
  title: "Forbidden",
  detail: "You are not a member of the project",
  status: HttpStatusCode.FORBIDDEN,
};

export const USER_HAS_NO_VIEW_ACCESS_TO_AI_PROVIDER_ASSIGNMENT: ProblemDetails =
  {
    type: "https://zup.fail/user-has-no-access-to-ai-provider-assignment",
    title: "Forbidden",
    detail:
      "You do not have access to the project's AI Providers. Please contact your account administrator for assistance.",
    status: HttpStatusCode.FORBIDDEN,
  };

export const USER_HAS_NO_EDIT_ACCESS_TO_AI_PROVIDER_ASSIGNMENT: ProblemDetails =
  {
    type: "https://zup.fail/user-has-no-access-to-ai-provider-assignment",
    title: "Forbidden",
    detail:
      "You do not have access to edit the project's AI Providers. Please contact your account administrator for assistance.",
    status: HttpStatusCode.FORBIDDEN,
  };

export const NO_ACCESS_TO_READ_ACCOUNT_MEMBERSHIP: ProblemDetails = {
  type: "https://zup.fail/no-access-to-read-account-membership",
  title: "Forbidden",
  detail:
    "Reading account membership requires account developer privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_TO_UPDATE_ACCOUNT_ROLES: ProblemDetails = {
  type: "https://zup.fail/no-access-to-update-account-roles",
  title: "Forbidden",
  detail:
    "Updating account roles requires account admin privileges. Please contact your account administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_TO_READ_PROJECT_MEMBERSHIP: ProblemDetails = {
  type: "https://zup.fail/no-access-to-read-project-membership",
  title: "Forbidden",
  detail:
    "Reading project membership requires being a project member. Please contact your project administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_TO_UPDATE_PROJECT_ROLES: ProblemDetails = {
  type: "https://zup.fail/no-access-to-update-project-roles",
  title: "Forbidden",
  detail:
    "Updating project roles requires project admin privileges. Please contact your project administrator for assistance.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_TO_CREATE_WORKING_COPY: ProblemDetails = {
  type: "https://zup.fail/no-access-to-create-working-copy",
  title: "Forbidden",
  detail:
    "You do not have access to create a working copy on this project. Make sure your role is at least a project developer and try again.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_TO_PROJECT_CUSTOM_DOMAIN: ProblemDetails = {
  type: "https://zup.fail/no-access-to-project-custom-domain",
  title: "Forbidden",
  detail:
    "You do not have access to view this project's custom domain configuration",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_EDIT_ACCESS_TO_PROJECT_CUSTOM_DOMAIN: ProblemDetails = {
  type: "https://zup.fail/no-edit-access-to-project-custom-domain",
  title: "Forbidden",
  detail:
    "You do not have access to edit this project's custom domain configuration",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_ACCESS_TO_MODIFY_ACCOUNT_CUSTOM_DOMAIN: ProblemDetails = {
  type: "https://zup.fail/no-access-to-modify-account-custom-domain",
  title: "Forbidden",
  detail:
    "You do not have access to modify this account's custom domain configuration",
  status: HttpStatusCode.FORBIDDEN,
};

export const USER_IS_PROJECT_MEMBER: ProblemDetails = {
  type: "https://zup.fail/user-is-project-member",
  title: "The user is already a project member.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const PROJECT_INVALID_GIT_CLONE: ProblemDetails = {
  type: "https://zup.fail/project-invalid-git-clone",
  title:
    "Project requires defaultBranch & sourceRepoUrl for creation from a GitHub repository.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const PROJECT_INVALID_GIT_REPO: ProblemDetails = {
  type: "https://zup.fail/project-invalid-git-repo",
  title:
    "The current source control repository is already in use by a Zuplo project",
  status: HttpStatusCode.BAD_REQUEST,
};

export const PROJECT_SHARING_REQUIRES_GIT_REPO: ProblemDetails = {
  type: "https://zup.fail/project-sharing-requires-git-repo",
  title: "The current project is not connected to a source control repository.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const USER_NO_ACCESS_GITHUB_REPO: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/user-no-access-github-repo",
  title:
    "You do not have access to the GitHub repository associated to the project. Ask your GitHub admin for access and try again.",
  detail: `User does not have access to the GitHub repository associated to the project. Go to Settings > Access > Collaborators in '${repositoryUrl}' to add a new collaborator.`,
  status: HttpStatusCode.FORBIDDEN,
});

export const USER_NO_PULL_ACCESS_GITHUB_REPO: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/user-no-access-github-repo",
  title:
    "You do not have pull access to the GitHub repository associated to the project. Ask your GitHub admin for access and try again.",
  detail: `User does not have access to the GitHub repository associated to the project. Go to Settings > Access > Collaborators in '${repositoryUrl}' to add a new collaborator.`,
  status: HttpStatusCode.FORBIDDEN,
});

export const GITHUB_USER_NO_READ_ACCESS_REPO: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/no-read-access-github-repo",
  title:
    "You do not have read access to the GitHub repository associated to the project. Ask your GitHub admin for access and try again.",
  detail: `User does not have access to the GitHub repository associated to the project. Go to Settings > Access > Collaborators in '${repositoryUrl}' to add a new collaborator.`,
  status: HttpStatusCode.FORBIDDEN,
});

export const GENERIC_GITHUB_BRANCH_INFO_ERROR: ProblemDetails = {
  type: "https://zup.fail/gh-branch-info-error",
  title:
    "There was an error getting branch information for the GitHub repository associated to the project.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const GITHUB_APP_NO_NAMESPACE_ACCESS: ProblemDetails = {
  type: "https://zup.fail/no-namespace-access-github-app",
  title:
    "The Zuplo GitHub app does not have access to the repositories under the namespace provided. Make sure to configure the GitHub Zuplo App on the repository.",
  status: HttpStatusCode.FORBIDDEN,
};

export const GITHUB_APP_NO_USER_ACCESS_: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/user-no-access-github-app-repo",
  title:
    "The Zuplo GitHub app does not have access to the repository. Make sure to configure the GitHub Zuplo App on the repository.",
  detail: `The Zuplo GitHub app has not been granted access to the repository '${repositoryUrl}'. Go to '${zuploGithubAppInstallationUrl}' to add the repository.`,
  status: HttpStatusCode.FORBIDDEN,
});

export const GITHUB_APP_CONFIGURATION_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/gh-app-not-found",
  title: "Global GitHub App configuration not found",
  status: HttpStatusCode.NOT_FOUND,
};

export const USER_NO_ACCESS_BITBUCKET_REPO: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/user-no-access-bitbucket-repo",
  title:
    "You do not have access to the Bitbucket repository associated to the project. Ask your Bitbucket admin for access and try again.",
  detail: `User does not have access to the Bitbucket repository associated to the project. Update the user permissions in '${repositoryUrl}' to add a new collaborator.`,
  status: HttpStatusCode.FORBIDDEN,
});

export const USER_NO_ACCESS_GITLAB_REPO: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/user-no-access-gitlab-repo",
  title:
    "You do not have access to the GitLab repository associated to the project. Ask your GitLab admin for access and try again.",
  detail: `User does not have access to the GitLab repository associated to the project. Update the user permissions in '${repositoryUrl}' to add a new collaborator.`,
  status: HttpStatusCode.FORBIDDEN,
});

export const USER_ACCOUNT_NOT_FS_MIGRATED: ProblemDetails = {
  type: "https://zup.fail/user-account-not-fs-migrated",
  title:
    "User account is in a plan that does not allow project sharing. Please contact your account admin.",
  status: HttpStatusCode.FORBIDDEN,
};

export const FAILED_TO_REVOKE_GH_TOKEN: ProblemDetails = {
  type: "https://zup.fail/failed-to-revoke-gh-token",
  title: "Failed to revoke GitHub token for the user",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
};

export const PROJECT_INVALID_NAME: ProblemDetails = {
  type: "https://zup.fail/project-invalid-name",
  title:
    "Project name is invalid, it only can contain letter, number and dashes.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const PROJECT_ALREADY_HAS_REPO: ProblemDetails = {
  type: "https://zup.fail/project-already-has-repo",
  title:
    "The current project has been previously linked to a source control repository",
  status: HttpStatusCode.BAD_REQUEST,
};

export const MAX_ALLOWED_PROJECTS_LIMIT_REACHED: ProblemDetails = {
  type: "https://zup.fail/max-allowed-projects-limit-reached",
  title: "Your account has reached the maximum number of projects allowed.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const FEATURE_FLAGS_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/feature-flags-not-found",
  title: "Error trying to retrieve feature flags for this user",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
};

export const GITHUB_INTEGRATION_ALREADY_EXISTS: ProblemDetails = {
  type: "https://zup.fail/github-integration-already-exists",
  title: "Error trying to create GitHub Integration, already exists.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const GITHUB_INTEGRATION_REPOSITORY_NOT_FOUND: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/github-integration-not-found",
  title: "Cannot find a project configured for this repository",
  status: HttpStatusCode.CONFLICT,
  detail: `The repository ${repositoryUrl} does not have a GitHub configured project.`,
});

export const GITHUB_REPOSITORY_NOT_FOUND: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/github-repo-not-found",
  title: "Cannot find a provided GitHub repository",
  status: HttpStatusCode.CONFLICT,
  detail: `The GitHub repository ${repositoryUrl} was not found.`,
});

export const GITHUB_INTEGRATION_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/github-integration-not-found",
  title: "Project is not integrated with GitHub",
  status: HttpStatusCode.NOT_FOUND,
  detail: `The project does not have a GitHub integration configured.`,
};

export const GITHUB_INTEGRATION_BRANCH_BEHIND: ProblemDetails = {
  type: "https://zup.fail/github-integration-branch-behind",
  title:
    "The current branch is behind, sync with remote repo for avoid conflicts.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const GITHUB_INTEGRATION_AUTHENTICATION_FAILED: ProblemDetails = {
  type: "https://zup.fail/github-integration-authentication-failed",
  title: "GitHub integration: Authentication failed",
  status: HttpStatusCode.FORBIDDEN,
};

export const GITHUB_INTEGRATION_QUERY_USER_INFO_FAILED: ProblemDetails = {
  type: "https://zup.fail/github-integration-query-user-info-failed",
  title: "Failed while requesting basic user info from GitHub",
  status: HttpStatusCode.FORBIDDEN,
};

export const GITHUB_INTEGRATION_DUPLICATE_REPO: ProblemDetailsFactory<{
  repositoryName: string;
  orgName: string;
}> = ({ repositoryName, orgName }) => ({
  type: "https://zup.fail/github-integration-duplicate-repo",
  title: "A repository with that name already exists in GitHub",
  details: `A repository named '${repositoryName}' already exists on GitHub org '${orgName}'.`,
  instance: repositoryName,
  status: HttpStatusCode.BAD_REQUEST,
});

export const GITHUB_INTEGRATION_FAILED_DURING_REPO_CREATION: ProblemDetailsFactory<{
  repositoryName: string;
  details: string;
}> = ({ repositoryName, details }) => ({
  type: "https://zup.fail/github-integration-failed-repo-creation",
  title: "Failed to create a new repository in GitHub",
  details,
  instance: repositoryName,
  status: HttpStatusCode.BAD_REQUEST,
});

export const GIT_CREATE_PROJECT_WITH_EMPTY_REPO: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/create-project-invalid-empty-repo",
  title:
    "The repository is empty and we can only create a project using a repository containing a valid Zuplo project. Try again with a Git repository containing a Zuplo project.",
  details: `Repository '${repositoryUrl}' is empty and we can only create a project using a repository containing a valid Zuplo project. Try again with a Git repository containing a Zuplo project.`,
  instance: repositoryUrl,
  status: HttpStatusCode.BAD_REQUEST,
});

export const GIT_CREATE_PROJECT_WITH_INVALID_REPO: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/create-project-invalid-git-repo",
  title:
    "We can only create a project using a repository containing a valid Zuplo project. Try again with a Git repository containing a Zuplo project.",
  details: `Repository '${repositoryUrl}' is not a repository containing a valid Zuplo project. Try again with a Git repository containing a Zuplo project.`,
  instance: repositoryUrl,
  status: HttpStatusCode.BAD_REQUEST,
});

export const GITHUB_INTEGRATION_INVALID_REPO: ProblemDetailsFactory<{
  repositoryUrl: string;
}> = ({ repositoryUrl }) => ({
  type: "https://zup.fail/github-integration-invalid-repo",
  title:
    "We can only connect to an empty repository or a repository containing a valid Zuplo project. Try again with an empty GitHub repository.",
  details: `Repository '${repositoryUrl}' is not an empty repository or a repository containing a valid Zuplo project. Try again with an empty GitHub repository.`,
  instance: repositoryUrl,
  status: HttpStatusCode.BAD_REQUEST,
});

export const BITBUCKET_QUERY_USER_INFO_FAILED: ProblemDetails = {
  type: "https://zup.fail/bitbucket-query-user-info-failed",
  title: "Failed while requesting basic user info from Bitbucket",
  status: HttpStatusCode.FORBIDDEN,
};

export const BITBUCKET_WORKSPACE_MISCONFIGURATION: ProblemDetails = {
  type: "https://zup.fail/bitbucket-workspace-misconfiguration",
  title:
    "Bitbucket source control configuration is missing workspace information",
  status: HttpStatusCode.FORBIDDEN,
};

export const BITBUCKET_FAILED_DURING_REPO_CREATION: ProblemDetailsFactory<{
  details: string;
}> = ({ details }) => ({
  type: "https://zup.fail/bitbucket-failed-repo-creation",
  title: "Failed to create a new repository in Bitbucket",
  details,
  status: HttpStatusCode.BAD_REQUEST,
});

export const GITLAB_QUERY_USER_INFO_FAILED: ProblemDetails = {
  type: "https://zup.fail/gitlab-query-user-info-failed",
  title: "Failed while requesting basic user info from GitLab",
  status: HttpStatusCode.FORBIDDEN,
};

export const GITLAB_FAILED_DURING_REPO_CREATION: ProblemDetailsFactory<{
  details: string;
}> = ({ details }) => ({
  type: "https://zup.fail/gitlab-failed-repo-creation",
  title: "Failed to create a new repository in GitLab",
  details,
  status: HttpStatusCode.BAD_REQUEST,
});

export const GITLAB_DUPLICATE_REPO: ProblemDetailsFactory<{
  repositoryName: string;
  orgName: string;
}> = ({ repositoryName, orgName }) => ({
  type: "https://zup.fail/gitlab-duplicate-repo",
  title: "A repository with that name already exists in GitLab",
  details: `A repository named '${repositoryName}' already exists in GitLab team '${orgName}'.`,
  instance: repositoryName,
  status: HttpStatusCode.BAD_REQUEST,
});

export const GITLAB_INSUFFICIENT_PERM_CREATE_REPO: ProblemDetailsFactory<{
  orgName: string;
}> = ({ orgName }) => ({
  type: "https://zup.fail/gitlab-create-repo-perm",
  title:
    "The user's GitLab group access level does not allow for repository creation.",
  details:
    "The user's GitLab group access level does not allow for repository creation.",
  instance: orgName,
  status: HttpStatusCode.BAD_REQUEST,
});

export const GITLAB_INSUFFICIENT_NAMESPACE_ACCESS: ProblemDetailsFactory<{
  namespaceLabel: string;
}> = ({ namespaceLabel }) => ({
  type: "https://zup.fail/gitlab-insufficient-namespace-access",
  title: `The user's GitLab access level does not allow the use of namespace '${namespaceLabel}'.`,
  details: `The user's GitLab access level does not allow the use of namespace '${namespaceLabel}'.`,
  instance: namespaceLabel,
  status: HttpStatusCode.BAD_REQUEST,
});

export const GITLAB_ACCESS_LEVEL_CHECK_FAIL: ProblemDetailsFactory<{
  orgName: string;
}> = ({ orgName }) => ({
  type: "https://zup.fail/gitlab-access-check-fail",
  title: "Failed to verify user's GitLab group access level",
  instance: orgName,
  status: HttpStatusCode.BAD_REQUEST,
});

export const CONSUMER_DOES_NOT_EXIST: ProblemDetails = {
  type: "https://zup.fail/consumer-does-not-exist",
  title: "Consumer does not exist or cannot be accessed.",
  status: HttpStatusCode.NOT_FOUND,
};

export const CONSUMER_CANNOT_BE_CREATED: ProblemDetails = {
  type: "https://zup.fail/consumer-not-created",
  title: "Failed to create consumer",
  status: HttpStatusCode.BAD_GATEWAY,
};

export const API_KEY_CANNOT_BE_CREATED: ProblemDetails = {
  type: "https://zup.fail/api-key-not-created",
  title: "Failed to create api key",
  status: HttpStatusCode.BAD_GATEWAY,
};

export const EXTERNAL_USER_NO_ACCESS: ProblemDetails = {
  type: "https://zup.fail/external-user-no-access",
  title: "User does not have access to this external user.",
  status: HttpStatusCode.UNAUTHORIZED,
};

export const EXTERNAL_USER_NOT_CONFIGURED: ProblemDetails = {
  type: "https://zup.fail/external-user-not-configured",
  title: "User is not setup as an External User (Key Manager)",
  status: HttpStatusCode.FORBIDDEN,
};

export const API_USER_NO_ACCESS: ProblemDetails = {
  type: "https://zup.fail/api-user-no-access",
  title: "Api user does not have access to this endpoint.",
  status: HttpStatusCode.FORBIDDEN,
};

export const EXTERNAL_SERVICE_GENERIC_ERROR: ProblemDetails = {
  type: "https://zup.fail/external-service-generic-error",
  title: "Unable to complete API request for External Service.",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
};

export const SOURCE_CONTROL_AUTHENTICATION_FAILED: ProblemDetailsFactory<{
  sourceControlProvider: "GitHub" | "Bitbucket" | "GitLab" | string;
}> = ({ sourceControlProvider }) => {
  const label = getSourceControlProviderLabel(sourceControlProvider);
  return {
    type: "https://zup.fail/source-control-authentication-failed",
    title: "Source provider authentication failed",
    detail: `Could not authenticate to ${label}`,
    status: HttpStatusCode.UNAUTHORIZED,
  };
};

export const SOURCE_CONTROL_REPO_NOT_FOUND: ProblemDetailsFactory<{
  sourceControlProvider: "GitHub" | "Bitbucket" | "GitLab" | string;
}> = ({ sourceControlProvider }) => {
  const label = getSourceControlProviderLabel(sourceControlProvider);
  return {
    type: "https://zup.fail/source-control-repo-not-found",
    title:
      "We cannot connect to the repository associated to the project, verify your source control access configuration and try again.",
    detail: `Could not connect to ${label} repository`,
    status: HttpStatusCode.NOT_FOUND,
  };
};

export const SOURCE_CONTROL_EMPTY_COMMIT_MESSAGE: ProblemDetails = {
  type: "https://zup.fail/source-control-empty-commit",
  title:
    "Commit operation failed because you provided an empty message. Please try again by providing a commit message.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const SOURCE_CONTROL_REPO_OPERATION_ERROR: ProblemDetailsFactory<{
  repoURL: string;
  operation: "commit" | "push" | "checkout";
}> = ({ repoURL, operation }) => {
  return {
    type: `https://zup.fail/source-control-repo-${operation}-error`,
    title: `Failed on ${operation} operation to repository '${repoURL}'. Verify you have read & write access to the repository and try again.`,
    detail: `Verify your source control configuration and make sure you have been granted read & write access to the repository`,
    status: HttpStatusCode.FORBIDDEN,
  };
};

export const SOURCE_CONTROL_REPO_WRITE_ACCESS_ISSUE: ProblemDetails = {
  type: "https://zup.fail/source-control-write-access-issue",
  title: `You do not have write access to the repository, verify your source control access configuration and try again.`,
  detail: `Verify your source control configuration and make sure you have been granted access to the repository`,
  status: HttpStatusCode.FORBIDDEN,
};

export const SOURCE_CONTROL_CONFIGURATION_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/source-control-configuration-not-found",
  title: "Source control configuration not found for this account.",
  status: HttpStatusCode.FORBIDDEN,
};

export const SOURCE_CONTROL_CREDENTIALS_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/source-control-credentials-not-found",
  title:
    "Source control credentials not found for this user. Verify your user's source control configuration and try again.",
  status: HttpStatusCode.FORBIDDEN,
};

export const FAILED_TO_REFRESH_SOURCE_CONTROL_CREDENTIALS: ProblemDetails = {
  type: "https://zup.fail/failed-to-refresh-source-control-credentials",
  title:
    "Failed to refresh Source Control credentials. Verify your user's source control configuration and try again.",
  status: HttpStatusCode.FORBIDDEN,
};

export const SOURCE_CONTROL_GH_APP_CONFIG_REQUIRED: ProblemDetails = {
  type: "https://zup.fail/new-gh-config-required",
  title:
    "Current Source Control credentials are using the previous Zuplo GitHup App. Re-authenticate using the latest Zuplo GitHup App via Profile UI and try again.",
  status: HttpStatusCode.FORBIDDEN,
};

export const SOURCE_CONTROL_GH_APP_REVOKED_ACCESS: ProblemDetails = {
  type: "https://zup.fail/gh-app-revoked-access",
  title:
    "Current Source Control credentials are invalid. Re-authenticate to GitHub via Profile UI and try again.",
  status: HttpStatusCode.UNAUTHORIZED,
};

export const FAILED_TO_REVOKE_SOURCE_CONTROL_CREDENTIALS: ProblemDetails = {
  type: "https://zup.fail/failed-to-revoke-source-control-credentials",
  title: "Failed to revoke Source Control access token for the user",
  status: HttpStatusCode.FORBIDDEN,
};

export const SOURCE_CONTROL_CONFIGURATION_INFO_MISSING: ProblemDetails = {
  type: "https://zup.fail/source-control-configuration-info-missing",
  title:
    "Source Control Configuration information is insufficient for this operation.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const SOURCE_CONTROL_CONFIGURATION_INVALID_PROVIDER: ProblemDetails = {
  type: "https://zup.fail/source-control-configuration-invalid-provider",
  title:
    "Source Control Configuration provider is invalid. Only GitHub, Bitbucket, and GitLab are supported.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const SOURCE_CONTROL_CONFIGURATION_BITBUCKET_WORKSPACE_MISSING: ProblemDetails =
  {
    type: "https://zup.fail/source-control-configuration-bb-workspace-missing",
    title:
      "Source Control Configuration for Bitbucket must include a workspace configuration (additionalMetadata).",
    status: HttpStatusCode.BAD_REQUEST,
  };

export const ACCOUNT_HAS_PREEXISTING_SOURCE_CONTROL_CONFIGURATION: ProblemDetails =
  {
    type: "https://zup.fail/preexisiting-source-control-configuration-on-account",
    title:
      "This account already has a Source Control Configuration for this provider.",
    detail:
      "This account has a pre-existing Source Control Configuration for this provider. Delete or update the existing configuration.",
    status: HttpStatusCode.BAD_REQUEST,
  };

export const SOURCE_CONTROL_INTEGRATION_BRANCH_BEHIND: ProblemDetails = {
  type: "https://zup.fail/source-control-integration-branch-behind",
  title:
    "The current branch is behind, sync with remote repo for avoid conflicts.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const SOURCE_CONTROL_REMOTE_BRANCH_EXISTS: ProblemDetails = {
  type: "https://zup.fail/source-control-integration-branch-behind",
  title:
    "The branch exists in the remote repository. Please try again with a different branch name.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const SOURCE_CONTROL_INTEGRATION_AUTHENTICATION_FAILED: ProblemDetails =
  {
    type: "https://zup.fail/source-control-integration-authentication-failed",
    title: "Source control integration: Authentication failed",
    status: HttpStatusCode.FORBIDDEN,
  };

export const THIRD_PARTY_APP_AUTH0_CLIENTS_ENDPOINT_ERROR: ProblemDetails = {
  type: "https://zup.fail/third-party-app-auth0-clients-endpoint-error",
  title: "Error Creating an Auth0 Client through tenant api",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
};

export const THIRD_PARTY_APP_AUTH0_CONFIG_DOES_NOT_EXIST: ProblemDetails = {
  type: "https://zup.fail/third-party-app-auth0-config-does-not-exist",
  title: "Auth0 Configuration does not exist for account and environment",
  status: HttpStatusCode.NOT_FOUND,
};
export const THIRD_PARTY_APP_AUTH0_CLIENT_NOT_FOUND_ERROR: ProblemDetails = {
  type: "https://zup.fail/third-party-app-auth0-client-not-found-error",
  title: "Third Party App Not Found",
  status: HttpStatusCode.NOT_FOUND,
};

export const THIRD_PARTY_APP_AUTH_SCOPE_CONFIG_ERROR: ProblemDetails = {
  type: "https://zup.fail/third-party-app-auth-scope-config-error",
  title: "API Scope configuration at Auth0 end Error",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
};

export const THIRD_PARTY_APP_CONNECTIONS_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/third-party-app-connections-not-found",
  title: "Cannot find auth0 tenant connections",
  status: HttpStatusCode.FAILED_DEPENDENCY,
};

export const THIRD_PARTY_APP_CONNECTION_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/third-party-app-connection-not-found",
  title: "Cannot find connection with the given name",
  status: HttpStatusCode.FAILED_DEPENDENCY,
};

export const THIRD_PARTY_APP_CANNOT_LINK_TPA_TO_CONNECTION: ProblemDetails = {
  type: "https://zup.fail/third-party-app-cannot-link-tpa-to-connection",
  title: "Cannot link a connection to a third party app",
  status: HttpStatusCode.FAILED_DEPENDENCY,
};

export const DUPLICATE_ENVIRONMENT_VARIABLE: ProblemDetails = {
  type: "https://zup.fail/duplicate-environment-variable",
  title: "Duplicate environment variable",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ENVIRONMENT_VARIABLE_VALIDATION_ERROR: ProblemDetails = {
  type: "https://zup.fail/environment-variables-validation-error",
  title: "Environment variable configuration is invalid",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ENVIRONMENT_VARIABLE_INVALID_ENVIRONMENT_TYPE: ProblemDetails = {
  type: "https://zup.fail/environment-variables-cannot-be-retrieved-invalid-env-type",
  title:
    "Env vars will not be retrieved since the deployment is from non valid environment type",
  status: HttpStatusCode.BAD_REQUEST,
};

export const NON_EXISTENT_ENVIRONMENT_VARIABLE: ProblemDetails = {
  type: "https://zup.fail/non-existent-environment-variable",
  title: "Environment variable doesn't exist",
  status: HttpStatusCode.NOT_FOUND,
};

export const DEPLOYMENT_NAME_MISSING: ProblemDetails = {
  type: "https://zup.fail/deployment-name-missing",
  title: "Deployment name missing",
  status: HttpStatusCode.BAD_REQUEST,
};

export const INVALIDLY_NAMED_ENVIRONMENT_VARIABLE: ProblemDetails = {
  type: "https://zup.fail/invalidly-named-environment-variable",
  title: "Environment variable needs a valid name",
  status: HttpStatusCode.BAD_REQUEST,
};

export const PERSONAL_OVERRIDE_ONLY_FOR_WORKING_COPY: ProblemDetails = {
  type: "https://zup.fail/personal-override-only-for-working-copy",
  title:
    "A personal override can only be used for a working-copy environment variable",
  status: HttpStatusCode.BAD_REQUEST,
};

export const TARGET_BRANCH_ONLY_FOR_PREVIEW: ProblemDetails = {
  type: "https://zup.fail/target-branch-only-for-preview",
  title: "A target branch can only be used for preview environment variables",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ENV_VAR_MAX_SIZE_LIMIT: ProblemDetails = {
  type: "https://zup.fail/environment-variable-maximum-size-limit",
  title: "Environment variables cannot exceed 5KB in size",
  status: HttpStatusCode.BAD_REQUEST,
};

export const INVALID_BRANCH_NAME: ProblemDetails = {
  type: "https://zup.fail/invalid-branch-name",
  title: "Branch name is invalid",
  status: HttpStatusCode.BAD_REQUEST,
};

export const OVERLAPPING_TARGETS: ProblemDetails = {
  type: "https://zup.fail/overlapping-targets",
  title:
    "The environments of this environment variable overlaps with an existing environment variable",
  status: HttpStatusCode.BAD_REQUEST,
};

export const CONFLICTING_TYPES: ProblemDetails = {
  type: "https://zup.fail/conflicting-types",
  title:
    "The type of this environment variable conflicts with an existing environment variable with the same name",
  status: HttpStatusCode.BAD_REQUEST,
};

export const NON_EMPTY_TARGETS_REQUIRED: ProblemDetails = {
  type: "https://zup.fail/non-empty-targets-required",
  title:
    "The environment targets for this environment variable cannot be empty.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const NO_ZUPLO_PREFIXED_VARIABLES: ProblemDetails = {
  type: "https://zup.fail/no-zuplo-prefixed-variables",
  title:
    "Environment variables should not start with the reserved prefix of ZUPLO or __ZUPLO",
  status: HttpStatusCode.BAD_REQUEST,
};

export const NO_GLOBAL_SYMBOLS: ProblemDetails = {
  type: "https://zup.fail/no-global-symbols",
  title: "Environment variables cannot be named after global variables.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const DEPLOYER_NON_VALID_DEPLOYMENT_ENVIRONMENT_TYPE: ProblemDetails = {
  type: "https://zup.fail/deployer-non-valid-deployment-environment-type",
  title: "Deployment cannot be different than preview or production",
  status: HttpStatusCode.BAD_REQUEST,
};

export const DEPLOYER_CANNOT_DEPLOY_USING_ENV_VARS_V2: ProblemDetails = {
  type: "https://zup.fail/deployer-cannot-deploy-using-env-vars-v2",
  title: "Deployer was not able to deploy zup using environment variables v2",
  status: HttpStatusCode.FORBIDDEN,
};

export const DELETING_ZUPLO_ENVIRONMENT_VARIABLES_ERROR: ProblemDetails = {
  type: "https://zup.fail/deleting-zuplo-environment-variables-error",
  title: "Problems deleting ZUPLO environment variables for deployment",
  status: HttpStatusCode.NOT_FOUND,
};

export const CANNOT_MODIFY_FILE_ON_READ_ONLY_ENVIRONMENT: ProblemDetailsFactory<{
  operation: "write" | "delete" | "edit" | "rename";
  path: string;
}> = ({ operation, path }) => ({
  type: "https://zup.fail/cannot-modify-file-on-read-only-environment",
  title: `Cannot modify file on read-only environment`,
  detail: `Cannot ${operation} file ${path} for a read-only environment. Read-only environments cannot be edited.`,
  status: HttpStatusCode.METHOD_NOT_ALLOWED,
});

export const CANNOT_SAVE_FILES_ON_READ_ONLY_ENVIRONMENT: ProblemDetailsFactory<
  Record<string, never>
> = () => ({
  type: "https://zup.fail/cannot-modify-file-on-read-only-environment",
  title: `Cannot modify files on read-only environment`,
  detail: `Cannot save files on a read-only environment. Read-only environments cannot be edited.`,
  status: HttpStatusCode.METHOD_NOT_ALLOWED,
});

export const MIGRATIONS_ONLY_ON_WORKING_COPY: ProblemDetails = {
  type: "https://zup.fail/migration-only-on-working-copy",
  title: `Migrations can only run on working copies.`,
  status: HttpStatusCode.BAD_REQUEST,
};

export const RUNTIME_VERSION_INCORRECT_FORMAT: ProblemDetails = {
  type: "https://zup.fail/migration-incorrect-runtime-version-format",
  title: `Runtime version is in an incorrect format.`,
  status: HttpStatusCode.BAD_REQUEST,
};

export const PACKAGE_JSON_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/no-pkg-file-found",
  title: `No package.json file found.`,
  status: HttpStatusCode.NOT_FOUND,
};

export const CANNOT_READ_PACKAGE_JSON: ProblemDetails = {
  type: "https://zup.fail/cannot-read-pkg-file",
  title: `Cannot read package.json file.`,
  status: HttpStatusCode.BAD_REQUEST,
};

export const CANNOT_FIND_SRC_DIRECTORY: ProblemDetails = {
  type: "https://zup.fail/cannot-find-src-dir",
  title: `Cannot find source directory.`,
  status: HttpStatusCode.BAD_REQUEST,
};

export const FAILED_DOWNLOAD_FROM_STORAGE: ProblemDetails = {
  type: "https://zup.fail/failed-download-storage",
  title: `Failed to download content from storage.`,
  status: HttpStatusCode.BAD_REQUEST,
};

export const CANNOT_CREATE_DIRECTORY_ON_READ_ONLY_ENVIRONMENT: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/cannot-modify-file-on-read-only-environment",
  title: `Cannot create directory on read-only environment`,
  detail: `Cannot create folder ${path} for a read-only environment. Read-only environments cannot be edited.`,
  status: HttpStatusCode.METHOD_NOT_ALLOWED,
});

export const CANNOT_CREATE_DIRECTORY_IN_NON_ALLOWED_LOCATION: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/directory-creation-in-non-allowed-location",
  title: "Directory creation attempted in non allowed location",
  detail: `Directory creation in ${path} is not allowed.`,
  instance: path,
  status: HttpStatusCode.BAD_REQUEST,
});

export const DIRECTORY_ALREADY_EXISTS: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/directory-already-exists",
  title: "Directory already exists",
  status: HttpStatusCode.BAD_REQUEST,
  detail: `Directory already exists at ${path}.`,
});

export const DIRECTORY_DOES_NOT_EXIST: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/directory-does-not-exist",
  title: "Directory does not exist",
  status: HttpStatusCode.BAD_REQUEST,
  detail: `No directory at ${path}`,
});

export const DIRECTORY_OR_FILE_DOES_NOT_EXIST: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/directory-or-file-does-not-exist",
  title: "Directory or File does not exist",
  status: HttpStatusCode.BAD_REQUEST,
  detail: `No file/directory at ${path}`,
});

export const DIRECTORY_CREATION_FAILED: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/directory-creation-failure",
  title: "Directory creation failed",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
  detail: `Failed to create directory at ${path}. Please try again or contact support.`,
});

export const FILE_RENAME_PATHS_MATCH: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/file-rename-paths-match",
  title: "New file name matches old file name",
  status: HttpStatusCode.BAD_REQUEST,
  detail: `Failed to rename file, the old path ${path} matched the provided new path. Please choose a different name.`,
});

export const FILE_RENAME_CANNOT_CHANGE_EXTENSION: ProblemDetailsFactory<{
  oldExtension: string;
  newExtension: string;
}> = ({ oldExtension, newExtension }) => ({
  type: "https://zup.fail/file-rename-cannot-change-extension",
  title: "Cannot change extension of renamed file",
  status: HttpStatusCode.BAD_REQUEST,
  detail: `Failed to rename file, the new extension ${newExtension} must match the old extension ${oldExtension}.`,
});

export const FILE_RENAME_FILE_ALREADY_EXISTS: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/file-rename-file-exists",
  title: "File already exists",
  status: HttpStatusCode.BAD_REQUEST,
  detail: `Failed to rename file, there already exists a file at ${path}. Please choose a different name.`,
});

export const FILE_RENAME_FAILED: ProblemDetailsFactory<{ path: string }> = ({
  path,
}) => ({
  type: "https://zup.fail/file-rename-failure",
  title: "File rename failed",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
  detail: `Failed to rename file ${path}. Please try again or contact support.`,
});

export const FILE_WRITE_FAILED: ProblemDetailsFactory<{ path: string }> = ({
  path,
}) => ({
  type: "https://zup.fail/file-write-failure",
  title: "File write failed",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
  detail: `Failed to write file ${path}. Please try again or contact support.`,
});

export const CANNOT_DELETE_ESSENTIAL_FILE: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/essential-file-deletion",
  title: "Cannot delete essential file",
  status: HttpStatusCode.BAD_REQUEST,
  detail: `File '${path}' cannot be deleted. It is an essential file.`,
});

export const CANNOT_DELETE_ESSENTIAL_DIRECTORY: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/essential-directory-deletion",
  title: "Cannot delete essential file",
  status: HttpStatusCode.BAD_REQUEST,
  detail: `Directory '${path}' cannot be deleted. It is an essential directory.`,
});

export const CANNOT_DELETE_SOLE_OPEN_API_FILE: ProblemDetailsFactory<
  void
> = () => ({
  type: "https://zup.fail/sole-open-api-file-deletion",
  title: "Cannot delete sole OpenAPI file",
  status: HttpStatusCode.BAD_REQUEST,
  detail: `Your project must have at least 1 OpenAPI file.`,
});

export const FILE_DELETE_FAILED: ProblemDetailsFactory<{ path: string }> = ({
  path,
}) => ({
  type: "https://zup.fail/file-delete-failure",
  title: "File deletion failed",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
  detail: `Failed to delete file ${path}. Please try again or contact support.`,
});

export const DIRECTORY_DELETE_FAILED: ProblemDetailsFactory<{
  path: string;
}> = ({ path }) => ({
  type: "https://zup.fail/directory-delete-failure",
  title: "Directory deletion failed",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
  detail: `Failed to delete directory ${path}. Please try again or contact support.`,
});

export const BUCKET_API_KEY_SERVICE_CONFLICT: ProblemDetails = {
  type: "https://zup.fail/bucket-api-key-service-error",
  title: "Bucket name conflicts",
  status: HttpStatusCode.CONFLICT,
};

export const BUCKET_NOT_FOUND: ProblemDetails = {
  type: "https://zup.fail/bucket-not-found",
  title: "Bucket cannot be found",
  status: HttpStatusCode.NOT_FOUND,
};

export const PROJECT_BUCKET_MISCONFIGURED: ProblemDetails = {
  type: "https://zup.fail/project-bucket-misconfigured",
  title:
    "Project bucket is misconfigured, make sure it is correctly configured for use on this project",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
};

export const UNABLE_UPGRADE_PLAN: ProblemDetails = {
  type: "https://zup.fail/cant-upgrade-plan",
  title: "Can't upgrade to selected plan",
  status: HttpStatusCode.BAD_REQUEST,
};

export const METERING_BUCKET_CREATION_FAILED: ProblemDetails = {
  type: "https://zup.fail/metering-bucket-creation-failed",
  title: "Failed to create metering buckets for project",
  status: HttpStatusCode.INTERNAL_SERVER_ERROR,
};

export const ACCOUNT_RBAC_DISABLED: ProblemDetails = {
  type: "https://zup.fail/account_rbac_disabled",
  title: "Forbidden",
  detail:
    "Your account does not have fine-grained RBAC feature enabled. Please contact support to enable this feature.",
  status: HttpStatusCode.FORBIDDEN,
};

export const RBAC_INVALID_EXPIRATION_DATE: ProblemDetails = {
  type: "https://zup.fail/rbac_invalid_expiration_date",
  title: "Bad Request",
  detail:
    "The expiration date provided cannot be in the past. Please provide a valid expiration date.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const RBACCONFIGURATION_DOES_NOT_EXISTS: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-does-not-exists",
  title: "Bad Request",
  detail:
    "The api key configuration does not exist or you don't have access to it.",
  status: HttpStatusCode.NOT_FOUND,
};

export const RBACCONFIGURATION_REQUIRE_ENVIRONMENTS: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-required-environments",
  title: "Bad Request",
  detail:
    "Please provide at least one environment value. Valid options include 'production', 'preview' and 'development'.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const RBACCONFIGURATION_INVALID_ENVIRONMENTS: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-invalid-environments",
  title: "Bad Request",
  detail:
    "Please provide at least one environment value. Valid options include 'production', 'preview' and 'development'.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const RBACCONFIGURATION_REQUIRE_PROJECTS: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-required-projects",
  title: "Bad Request",
  detail: "Please provide at least one project to configure access for.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const RBACCONFIGURATION_ACCOUNT_HAS_NO_PROJECTS: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-no-projects",
  title: "Bad Request",
  detail:
    "The account does not have any projects to configure. Please create at least one project before configuring api key access.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const RBACCONFIGURATION_INVALID_PROJECT_PROVIDED: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-invalid-project",
  title: "Bad Request",
  detail:
    "One or more of the projects provided is not part of the account or does not exist. Make sure all the projects are valid and try again.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const RBACCONFIGURATION_INVALID_OPENFGA_CONFIG: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-invalid-openfga-config",
  title: "Bad Gateway",
  detail:
    "The provided configuration caused an unexpected error. Please contact support.",
  status: HttpStatusCode.BAD_GATEWAY,
};

export const RBACCONFIGURATION_DELETE_MISCONFIGURATION: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-delete-misconfiguration",
  title: "Bad Request",
  detail:
    "The provided configuration was not correctly created and cannot be deleted. Please contact support.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const RBACCONFIGURATION_MISCONFIGURATION: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-misconfiguration",
  title: "Bad Request",
  detail:
    "The provided configuration was not correctly created and cannot be used. Please contact support.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const RBACCONFIGURATION_CONSUMER_LOCKED: ProblemDetails = {
  type: "https://zup.fail/rbacconfiguration-consumer-locked",
  title: "Forbidden",
  detail: "The provided consumer is locked and can't be modified or deleted.",
  status: HttpStatusCode.FORBIDDEN,
};

export const USER_HAS_NO_ACCESS_TO_CONSUMER: ProblemDetails = {
  type: "https://zup.fail/forbidden",
  title: "Forbidden",
  detail: "You are not authorized to access the consumer resource.",
  status: HttpStatusCode.FORBIDDEN,
};

export const INVALID_USER_ROLE: ProblemDetails = {
  type: "https://zup.fail/invalid-user-role",
  title: "Bad Request",
  detail:
    "You provided an invalid user role. Valid options include 'admin', 'developer' and 'member'.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const USER_DOES_NOT_EXIST: ProblemDetails = {
  type: "https://zup.fail/user-does-not-exist",
  title: "Forbidden",
  detail: "You are not authorized to access the user resource.",
  status: HttpStatusCode.FORBIDDEN,
};

export const USER_CANNOT_EDIT_OWN_ROLE: ProblemDetails = {
  type: "https://zup.fail/user-edit-itself",
  title: "Forbidden",
  detail: "You are not authorized to edit your own access role.",
  status: HttpStatusCode.FORBIDDEN,
};

export const USER_HAS_NO_ACCESS_TO_PROJECT_ENVIRONMENT: ProblemDetails = {
  type: "https://zup.fail/user-has-no-access-to-project-env",
  title: "Forbidden",
  detail: "You are not authorized to access this project environment.",
  status: HttpStatusCode.FORBIDDEN,
};

export const USER_HAS_NO_EDIT_ACCESS_TO_PROJECT_ENVIRONMENT: ProblemDetails = {
  type: "https://zup.fail/user-has-no-edit-access-to-project-env",
  title: "Forbidden",
  detail: "You are not authorized to edit this project environment.",
  status: HttpStatusCode.FORBIDDEN,
};

export const USER_HAS_NO_DEPLOY_ACCESS_TO_PROJECT_ENVIRONMENT: ProblemDetails =
  {
    type: "https://zup.fail/user-has-no-deploy-access-to-project-env",
    title: "Forbidden",
    detail: "You are not authorized to deploy this project environment.",
    status: HttpStatusCode.FORBIDDEN,
  };

export const ACCOUNT_ADMIN_INVALID_PROJECT_ROLE_DOWNGRADE: ProblemDetails = {
  type: "https://zup.fail/account-admin-invalid-project-role-downgrade",
  title: "Bad Request",
  detail:
    "An account administrator cannot be downgraded to a non-administrator role in a project.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const USER_HAS_NO_ENV_VAR_VIEW_ACCESS: ProblemDetails = {
  type: "https://zup.fail/user-no-env-var-view-access",
  title: "Forbidden",
  detail: "You are not authorized to view the project's environment variables.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_PROD_CUD_ENV_VAR_ACCESS: ProblemDetails = {
  type: "https://zup.fail/user-no-prod-env-var-access",
  title: "Forbidden",
  detail:
    "You are not authorized to modify the project's production environment variables.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_PREVIEW_CUD_ENV_VAR_ACCESS: ProblemDetails = {
  type: "https://zup.fail/user-no-dev-env-var-access",
  title: "Forbidden",
  detail:
    "You are not authorized to modify the project's preview environment variables.",
  status: HttpStatusCode.FORBIDDEN,
};

export const NO_WORKINGCOPY_CUD_ENV_VAR_ACCESS: ProblemDetails = {
  type: "https://zup.fail/user-no-working-copy-env-var-access",
  title: "Forbidden",
  detail:
    "You are not authorized to modify the project's working copy environment variables.",
  status: HttpStatusCode.FORBIDDEN,
};

export const MISCONFIGURED_ENV_VAR: ProblemDetails = {
  type: "https://zup.fail/misconfigured-env-var",
  title: "Bad Request",
  detail:
    "The environment variable is not correctly configured on any environment. Please contact support.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_ALREADY_RBAC_ENABLED: ProblemDetails = {
  type: "https://zup.fail/misconfigured-env-var",
  title: "Bad Request",
  detail: "The account has been previously migrated to use RBAC.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const ACCOUNT_MISCONFIGURED_FOR_RBAC: ProblemDetails = {
  type: "https://zup.fail/misconfigured-env-var",
  title: "Bad Request",
  detail:
    "This account has conflicting account roles and cannot be self-migrated to use RBAC. Please contact support.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const USER_EMAIL_MISMATCH: ProblemDetails = {
  type: "https://zup.fail/user-email-mismatch",
  title: "Bad Request",
  detail:
    "The email addresses of the primary and secondary identities do not match. Please ensure that all identities belong to the same user/email.",
  status: HttpStatusCode.BAD_REQUEST,
};

export const CANNOT_DELETE_PROJECT_ROLE: ProblemDetailsFactory<{
  detail: string;
}> = ({ detail }) => ({
  type: "https://zup.fail/failed-deleting-user-project-role",
  title:
    "Failed to delete the user's role on the project. Please contact support.",
  detail: detail,
  status: HttpStatusCode.BAD_REQUEST,
});
