cimport cython
cimport constants_inf

AIStatus2Text = {
    AIAvailabilityEnum.NONE: "None",
    AIAvailabilityEnum.DOWNLOADING: "Downloading",
    AIAvailabilityEnum.CONVERTING: "Converting",
    AIAvailabilityEnum.UPLOADING: "Uploading",
    AIAvailabilityEnum.ENABLED: "Enabled",
    AIAvailabilityEnum.WARNING: "Warning",
    AIAvailabilityEnum.ERROR: "Error",
}

cdef class AIAvailabilityStatus:
    def __init__(self):
        self.status = AIAvailabilityEnum.NONE
        self.error_message = ""

    def __str__(self):
        with self._lock:
            status_text = AIStatus2Text.get(self.status, "Unknown")
            error_text = self.error_message if self.error_message else ""
            return f"{status_text} {error_text}"

    cdef set_status(self, int status, str error_message=""):
        log_message = ""
        with self._lock:
            self.status = status
            self.error_message = error_message
            status_text = AIStatus2Text.get(self.status, "Unknown")
            error_text = self.error_message if self.error_message else ""
            log_message = f"{status_text} {error_text}"

        if error_message:
            constants_inf.logerror(<str>error_message)
        else:
            constants_inf.log(<str>log_message)
