from enum import Enum
from typing import Optional, List

from pydantic import BaseModel, Field


class CliCommand(str, Enum):
    VERSION = "VERSION"
    CONNECT = "CONNECT"
    PROJECT_CLONE = "PROJECT_CLONE"
    PROJECT_INIT = "PROJECT_INIT"
    PROJECT_RUN = "PROJECT_RUN"
    PROJECT_CHECKOUT = "PROJECT_CHECKOUT"
    PROJECT_PULL = "PROJECT_PULL"
    PROJECT_RESET = "PROJECT_RESET"
    PROJECT_INFERENCE_SIMULATOR_RUN = "PROJECT_INFERENCE_SIMULATOR_RUN"
    PROJECT_INFERENCE_SIMULATOR_SAVE_METADATA = "PROJECT_INFERENCE_SIMULATOR_SAVE_METADATA"
    PROJECT_INFERENCE_SIMULATOR_PUSH = "PROJECT_INFERENCE_SIMULATOR_PUSH"
    PROJECT_INFERENCE_SIMULATOR_LS = "PROJECT_INFERENCE_SIMULATOR_LS"
    PROJECT_INFERENCE_SIMULATOR_LOGS = "PROJECT_INFERENCE_SIMULATOR_LOGS"
    PROJECT_MODEL_LS = "PROJECT_MODEL_LS"
    PROJECT_MODEL_DEPLOY_INSTANCE = "PROJECT_MODEL_DEPLOY_INSTANCE"
    PROJECT_MODEL_DEPLOY_SAGEMAKER = "PROJECT_MODEL_DEPLOY_SAGEMAKER"
    PROJECT_TASK_CANCEL = "PROJECT_TASK_CANCEL"
    PROJECT_TASK_LS = "PROJECT_TASK_LS"
    PROJECT_TASK_LOGS = "PROJECT_TASK_LOGS"
    PROJECT_CONFIG_SET_DEFAULT_CONTAINER = "PROJECT_CONFIG_SET_DEFAULT_CONTAINER"
    PROJECT_CONFIG_GET = "PROJECT_CONFIG_GET"
    PROJECT_ATTACH_INSTANCE = "PROJECT_ATTACH_INSTANCE"
    PROJECT_LS = "PROJECT_LS"
    PROJECT_DETACH_INSTANCE = "PROJECT_DETACH_INSTANCE"
    PROJECT_DELETE = "PROJECT_DELETE"
    CONTAINER_LS = "CONTAINER_LS"
    CONTAINER_INFO = "CONTAINER_INFO"
    CONTAINER_CONNECT = "CONTAINER_CONNECT"
    CONTAINER_UPLOAD = "CONTAINER_UPLOAD"
    CONTAINER_DOWNLOAD = "CONTAINER_DOWNLOAD"
    CONTAINER_CREATE = "CONTAINER_CREATE"
    CONTAINER_START = "CONTAINER_START"
    CONTAINER_STOP = "CONTAINER_STOP"
    CONTAINER_DELETE = "CONTAINER_DELETE"
    CONTAINER_RESTART = "CONTAINER_RESTART"
    CONTAINER_LOGS = "CONTAINER_LOGS"
    CONTAINER_IMAGE_LS = "CONTAINER_IMAGE_LS"
    INSTANCE_RENTED_LS = "INSTANCE_RENTED_LS"
    INSTANCE_RENTED_CONNECT = "INSTANCE_RENTED_CONNECT"
    INSTANCE_RENTED_CREATE = "INSTANCE_RENTED_CREATE"
    INSTANCE_RENTED_TERMINATE = "INSTANCE_RENTED_TERMINATE"
    INSTANCE_RENTED_RESTART = "INSTANCE_RENTED_RESTART"
    INSTANCE_SELF_HOSTED_LS = "INSTANCE_SELF_HOSTED_LS"
    INSTANCE_SELF_HOSTED_CONNECT = "INSTANCE_SELF_HOSTED_CONNECT"
    CONFIG_GET = "CONFIG_GET"
    CONFIG_SET = "CONFIG_SET"
    CONFIG_CLEAR = "CONFIG_CLEAR"
    CONFIG_UPLOAD_SSH_KEY = "CONFIG_UPLOAD_SSH_KEY"


class CliCommandAvailability(str, Enum):
    ALLOWED = "ALLOWED"
    RESTRICTED = "RESTRICTED"
    DEPRECATED = "DEPRECATED"


ALWAYS_AVAILABLE_COMMANDS = [
    CliCommand.VERSION,
    CliCommand.PROJECT_CONFIG_GET,
    CliCommand.CONFIG_GET,
    CliCommand.CONFIG_SET,
    CliCommand.CONFIG_CLEAR,
]


class CliCommandMetadata(BaseModel):
    instanceOfferProviderNames: Optional[List[str]] = Field(None, alias='instanceOfferProviderNames')
    instanceOfferGpuNames: Optional[List[str]] = Field(None, alias='instanceOfferGpuNames')
