from dataclasses import dataclass
from typing import Optional, List, Any

from ._SchemaModel import SchemaModel
from ._SchemaPropertyFormatEnum import SchemaPropertyFormatEnum
from ._SchemaPropertyTypeEnum import SchemaPropertyTypeEnum
from ..utils import generate_uuid


@dataclass
class SchemaPropertyModel(SchemaModel):
    type: SchemaPropertyTypeEnum
    format: Optional[SchemaPropertyFormatEnum] = None
    enum: List[Any] = None
    default: Any = None
    example: Any = None

    def _scalar_key(self) -> str:
        format_part = str(self.format) if self.format is not None else ""
        return f"{self.type}:{format_part}"

    def get_schema_uuid(self) -> str:
        if getattr(self, '_schema_uuid', None) is not None:
            return super().get_schema_uuid()
        return generate_uuid(self._scalar_key())

    def get_schema_name(self) -> str:
        if getattr(self, '_schema_name', None) is not None:
            return super().get_schema_name()
        format_part = str(self.format) if self.format is not None else ""
        if format_part:
            return f"{self.type}-{format_part}"
        return str(self.type)