from __future__ import annotations

import sys
from dataclasses import dataclass, field
from datetime import datetime, timezone

if sys.version_info >= (3, 11):
    from enum import StrEnum
else:
    from enum import Enum

    class StrEnum(str, Enum):
        pass


from typing import Any
from uuid import uuid4


class AssetLibraryKind(StrEnum):
    VIDEO = "video"
    VOICE = "voice"


class IngestJobStatus(StrEnum):
    PENDING = "pending"
    PROCESSING = "processing"
    COMPLETED = "completed"
    FAILED = "failed"


class ClassificationJobStatus(StrEnum):
    PENDING = "pending"
    PROCESSING = "processing"
    COMPLETED = "completed"
    FAILED = "failed"


class AssetClassification(StrEnum):
    """Asset classification categories."""

    SCENIC = "scenic"  # 风景
    PRODUCT = "product"  # 产品
    PERSON = "person"  # 人物
    ANIMAL = "animal"  # 动物
    FOOD = "food"  # 美食
    TECH = "tech"  # 科技
    SPORT = "sport"  # 运动
    MUSIC = "music"  # 音乐
    OTHER = "other"  # 其他


@dataclass(slots=True)
class ClassificationJob:
    id: str
    project_id: str
    asset_id: str
    status: ClassificationJobStatus = ClassificationJobStatus.PENDING
    classification: str = ""  # Result: AssetClassification value
    confidence: float = 0.0  # 0.0 - 1.0
    error_message: str = ""
    created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
    updated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))

    @classmethod
    def create(
        cls,
        project_id: str,
        asset_id: str,
    ) -> "ClassificationJob":
        if not project_id.strip():
            raise ValueError("project_id 不能为空")
        if not asset_id.strip():
            raise ValueError("asset_id 不能为空")
        return cls(
            id=uuid4().hex,
            project_id=project_id.strip(),
            asset_id=asset_id.strip(),
        )
