# from PySide6.QtCore import QPointF, QRectF, QSizeF
# -*- coding: utf-8 -*-
class Constant:
    # invalid_point = QPointF(-123.4, -234.71) # 无效点
    # invalid_rect = QRectF(invalid_point, QSizeF(0, 0)) # 无效矩形
    service_yml_path = 'config/service/dsp_%s_service.yml'  # 服务配置路径
    kafka_yml_path = 'config/kafka/dsp_%s_kafka.yml'        # kafka配置路径
    aliyun_yml_path = "config/aliyun/dsp_%s_aliyun.yml"     # 阿里云配置路径
    baidu_yml_path = 'config/baidu/dsp_%s_baidu.yml'        # 百度配置路径
    pull_frame_width = 1400 # 拉流帧宽度

    LLM_MODE_NONE = 0
    LLM_MODE_NONCHAT = 1
    LLM_MODE_CHAT = 2
    LLM_MODE_EMBEDDING = 3
    LLM_MODE_LOCAL_OLLAMA = 4
    
    LLM_PROMPT_TEMPLATE_METHOD_FORMAT = "format"
    LLM_PROMPT_TEMPLATE_METHOD_INVOKE = "invoke"
    
    LLM_PROMPT_VALUE_STR = "str"
    LLM_PROMPT_VALUE_MESSAGES = "messages"
    LLM_PROMPT_VALUE_VALUE = "promptValue"
    
    INPUT_NONE = 0
    INPUT_PULL_STREAM = 1
    INPUT_NET_CAMERA = 2
    INPUT_USB_CAMERA = 3
    INPUT_LOCAL_VIDEO = 4
    INPUT_LOCAL_DIR = 5    
    INPUT_LOCAL_FILE = 6
    INPUT_LOCAL_LABELLED_DIR = 7
    INPUT_LOCAL_LABELLED_ZIP = 8

    SYSTEM_BUTTON_SNAP = 1
    SYSTEM_BUTTON_CLEAR_LOG = 2

    MODE_OCR = 7
    
    WEB_OWNER_NONE = 0
    WEB_OWNER_ALG_TEST = 1
    WEB_OWNER_LLM = 2

    PAGE_MODE_NONE = 0
    PAGE_MODE_VIDEO = 1
    PAGE_MODE_LABELLING = 2
    PAGE_MODE_ALG_TEST = 3
    PAGE_MODE_WEB = 4
    PAGE_MODE_LLM = 5
    PAGE_MODE_CONFIG = 6

    ALG_TEST_LOAD_DATA = 1
    ALG_TEST_TRAIN = 2
    ALG_TEST_INFER = 3

    ALG_STATUS_NOTHING = 0       # 啥也没干
    ALG_STATUS_MODEL_READY = 1   # 模型已就绪
    ALG_STATUS_DATA_LOADED = 2   # 加载已数据/加载中
    ALG_STATUS_TRAINED = 4       # 训练完成/训练中
    ALG_STATUS_INFER = 8         # 推理完成/推理中

    UTF_8 = "utf-8" # 编码格式

    COLOR = (
        [0, 0, 255],
        [255, 0, 0],
        [211, 0, 148],
        [0, 127, 0],
        [0, 69, 255],
        [0, 255, 0],
        [255, 0, 255],
        [0, 0, 127],
        [127, 0, 255],
        [255, 129, 0],
        [139, 139, 0],
        [255, 255, 0],
        [127, 255, 0],
        [0, 127, 255],
        [0, 255, 127],
        [255, 127, 255],
        [8, 101, 139],
        [171, 130, 255],
        [139, 112, 74],
        [205, 205, 180])

    ONLINE = "online"
    OFFLINE = "offline"
    PHOTO = "photo"
    RECORDING = "recording"

    ONLINE_START_SCHEMA = {
        "request_id": {
            'type': 'string',
            'required': True,
            'empty': False,
            'regex': r'^[a-zA-Z0-9]{1,36}$'
        },
        "command": {
            'type': 'string',
            'required': True,
            'allowed': ["start"]
        },
        "pull_url": {
            'type': 'string',
            'required': True,
            'empty': False,
            'maxlength': 255
        },
        "push_url": {
            'type': 'string',
            'required': True,
            'empty': False,
            'maxlength': 255
        },
        "logo_url": {
            'type': 'string',
            'required': False,
            'nullable': True,
            'maxlength': 255
        },
        "models": {
            'type': 'list',
            'required': True,
            'nullable': False,
            'minlength': 1,
            'maxlength': 3,
            'schema': {
                'type': 'dict',
                'required': True,
                'schema': {
                    "code": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "categories",
                        'regex': r'^[a-zA-Z0-9]{1,255}$'
                    },
                    "is_video": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "code",
                        'allowed': ["0", "1"]
                    },
                    "is_image": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "code",
                        'allowed': ["0", "1"]
                    },
                    "categories": {
                        'type': 'list',
                        'required': True,
                        'dependencies': "code",
                        'schema': {
                            'type': 'dict',
                            'required': True,
                            'schema': {
                                "id": {
                                    'type': 'string',
                                    'required': True,
                                    'empty': False,
                                    'regex': r'^[a-zA-Z0-9]{0,255}$'},
                                "config": {
                                    'type': 'dict',
                                    'required': False,
                                    'dependencies': "id",
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    ONLINE_STOP_SCHEMA = {
        "request_id": {
            'type': 'string',
            'required': True,
            'empty': False,
            'regex': r'^[a-zA-Z0-9]{1,36}$'
        },
        "command": {
            'type': 'string',
            'required': True,
            'allowed': ["stop"]
        }
    }

    OFFLINE_START_SCHEMA = {
        "request_id": {
            'type': 'string',
            'required': True,
            'empty': False,
            'regex': r'^[a-zA-Z0-9]{1,36}$'
        },
        "command": {
            'type': 'string',
            'required': True,
            'allowed': ["start"]
        },
        "push_url": {
            'type': 'string',
            'required': True,
            'empty': False,
            'maxlength': 255
        },
        "pull_url": {
            'type': 'string',
            'required': True,
            'empty': False,
            'maxlength': 255
        },
        "logo_url": {
            'type': 'string',
            'required': False,
            'nullable': True,
            'maxlength': 255
        },
        "models": {
            'type': 'list',
            'required': True,
            'maxlength': 3,
            'minlength': 1,
            'schema': {
                'type': 'dict',
                'required': True,
                'schema': {
                    "code": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "categories",
                        'regex': r'^[a-zA-Z0-9]{1,255}$'
                    },
                    "is_video": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "code",
                        'allowed': ["0", "1"]
                    },
                    "is_image": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "code",
                        'allowed': ["0", "1"]
                    },
                    "categories": {
                        'type': 'list',
                        'required': True,
                        'dependencies': "code",
                        'schema': {
                            'type': 'dict',
                            'required': True,
                            'schema': {
                                "id": {
                                    'type': 'string',
                                    'required': True,
                                    'empty': False,
                                    'regex': r'^[a-zA-Z0-9]{0,255}$'},
                                "config": {
                                    'type': 'dict',
                                    'required': False,
                                    'dependencies': "id",
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    OFFLINE_STOP_SCHEMA = {
        "request_id": {
            'type': 'string',
            'required': True,
            'empty': False,
            'regex': r'^[a-zA-Z0-9]{1,36}$'
        },
        "command": {
            'type': 'string',
            'required': True,
            'allowed': ["stop"]
        }
    }

    IMAGE_SCHEMA = {
        "request_id": {
            'type': 'string',
            'required': True,
            'empty': False,
            'regex': r'^[a-zA-Z0-9]{1,36}$'
        },
        "command": {
            'type': 'string',
            'required': True,
            'allowed': ["start"]
        },
        "logo_url": {
            'type': 'string',
            'required': False,
            'nullable': True,
            'maxlength': 255
        },
        "image_urls": {
            'type': 'list',
            'required': True,
            'minlength': 1,
            'schema': {
                'type': 'string',
                'required': True,
                'empty': False,
                'maxlength': 5000
            }
        },
        "models": {
            'type': 'list',
            'required': True,
            'schema': {
                'type': 'dict',
                'required': True,
                'schema': {
                    "code": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "categories",
                        'regex': r'^[a-zA-Z0-9]{1,255}$'
                    },
                    "is_video": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "code",
                        'allowed': ["0", "1"]
                    },
                    "is_image": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "code",
                        'allowed': ["0", "1"]
                    },
                    "categories": {
                        'type': 'list',
                        'required': True,
                        'dependencies': "code",
                        'schema': {
                            'type': 'dict',
                            'required': True,
                            'schema': {
                                "id": {
                                    'type': 'string',
                                    'required': True,
                                    'empty': False,
                                    'regex': r'^[a-zA-Z0-9]{0,255}$'},
                                "config": {
                                    'type': 'dict',
                                    'required': False,
                                    'dependencies': "id",
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    RECORDING_START_SCHEMA = {
        "request_id": {
            'type': 'string',
            'required': True,
            'empty': False,
            'regex': r'^[a-zA-Z0-9]{1,36}$'
        },
        "command": {
            'type': 'string',
            'required': True,
            'allowed': ["start"]
        },
        "pull_url": {
            'type': 'string',
            'required': True,
            'empty': False,
            'maxlength': 255
        },
        "push_url": {
            'type': 'string',
            'required': False,
            'empty': True,
            'maxlength': 255
        },
        "logo_url": {
            'type': 'string',
            'required': False,
            'nullable': True,
            'maxlength': 255
        }
    }

    RECORDING_STOP_SCHEMA = {
        "request_id": {
            'type': 'string',
            'required': True,
            'empty': False,
            'regex': r'^[a-zA-Z0-9]{1,36}$'
        },
        "command": {
            'type': 'string',
            'required': True,
            'allowed': ["stop"]
        }
    }

    PULL2PUSH_START_SCHEMA = {
        "request_id": {
            'type': 'string',
            'required': True,
            'empty': False,
            'regex': r'^[a-zA-Z0-9]{1,36}$'
        },
        "command": {
            'type': 'string',
            'required': True,
            'allowed': ["start"]
        },
        "video_urls": {
            'type': 'list',
            'required': True,
            'nullable': False,
            'schema': {
                'type': 'dict',
                'required': True,
                'schema': {
                    "id": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "pull_url",
                        'regex': r'^[a-zA-Z0-9]{1,255}$'
                    },
                    "pull_url": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "push_url",
                        'regex': r'^(https|http|rtsp|rtmp|artc|webrtc|ws)://\w.+$'
                    },
                    "push_url": {
                        'type': 'string',
                        'required': True,
                        'empty': False,
                        'dependencies': "id",
                        'regex': r'^(https|http|rtsp|rtmp|artc|webrtc|ws)://\w.+$'
                    }
                }
            }
        }
    }

    PULL2PUSH_STOP_SCHEMA = {
        "request_id": {
            'type': 'string',
            'required': True,
            'empty': False,
            'regex': r'^[a-zA-Z0-9]{1,36}$'
        },
        "command": {
            'type': 'string',
            'required': True,
            'allowed': ["start", "stop"]
        },
        "video_ids": {
            'type': 'list',
            'required': False,
            'nullable': True,
            'schema': {
                'type': 'string',
                'required': True,
                'empty': False,
                'regex': r'^[a-zA-Z0-9]{1,255}$'
            }
        }
    }
