from enum import Enum, unique


@unique
class ImportScriptStatusCodeTranslator(Enum):
    """
         The following class holds error messages & error code related to scenarios in which the import
         script encounter which issues.
     """
    EXPORT_FILE_DOES_NOT_EXIST = ("Export file does not exist or does not accessible for the script please check the export file path and permissions", 432)
    EXPORT_FILE_EXTENSION_IS_NOT_SUPPORTED = ("Export file file extension is not supported the export file should be format: ExportFile.tar.gz", 433)
    CORRUPTED_EXPORT_FILE = ("Export file is corrupted", 434)
    INVALID_EXPORT_FILE_DATA = ("Export file data is invalid please check it's the correct export file", 435)
    FAILED_TO_GET_PRE_SIGNED_URL = ("Failed to retrieve S3 pre-signed URL please check the AWS credentials and permissions and try again", 436)
    CTM_MIGRATION_NOT_ALLOWED = (
        "Cannot migrate data of Control-M/Server '{ctm_name}' to Control-M SaaS. "
        "Please verify one of the following: "
        "(1) the Control-M/Server is a Control-M SaaS server and not Self-Hosted (on-premises); "
        "(2) the Control-M/Server exists in the Control-M SaaS environment; "
        "(3) the Control-M/Server name exactly matches the one defined in Control-M SaaS; "
        "(4) the AWS credentials and permissions are valid. "
        "Server response: {detail}",
        440)
    FAILED_TO_UPLOAD_EXPORT_FILE = ("Failed to upload the export file to S3 please check the AWS credentials and permissions and try again", 437)
    FAILED_TO_START_MIGRATION_IMPORT_PROCESS = ("Failed to start the migration process please check the AWS credentials and permissions and try again", 438)
    FAILED_TO_POLL_MIGRATION_IMPORT_PROCESS_STATUS = ("Failed to poll the migration process status please check network connection and try again", 439)
    CTM_IMPORT_FAILED = ("The data migration of Control-M/Server '{ctm_name}' failed to import into Control-M SaaS. Details: {detail}", 441)
    FAILED_WITH_INTERNAL_SERVER_ERROR = ("Internal Server Error please try again", 500)

    def __new__(cls, message: str, code: int) -> Enum:
        obj = object.__new__(cls)
        obj._value_ = message
        obj.message = message
        obj.code = code
        return obj

    @classmethod
    def error_code_translator(cls, err_msg: str) -> int:
        """
        Translates an error message to its appropriate error code.
        """
        for enum_member in cls:
            if enum_member.message == err_msg:
                return enum_member.code
        return cls.GENERAL_ERROR.code
