from typing import ClassVar

from .spec import OtelGenAISpecification
from .types import MODALITY_VALUES, OPTIONAL, REQUIRED, AttributeSpec


class OtelGenAIInputMessageGenericPartSpecification(OtelGenAISpecification):
    """Generic input message part specification with only type validation."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
        ),
    }


class OtelGenAIInputMessageTextPartSpecification(OtelGenAISpecification):
    """Text input message part specification with required content."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "content": AttributeSpec(
            name="content",
            requirement=REQUIRED,
            type="string",
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["text"],
        ),
    }


class OtelGenAIInputMessageToolCallRequestPartSpecification(OtelGenAISpecification):
    """Tool call request input message part specification with required name."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "arguments": AttributeSpec(
            name="arguments",
            requirement=OPTIONAL,
            type="any",
        ),
        "id": AttributeSpec(
            name="id",
            requirement=OPTIONAL,
            type="string",
        ),
        "name": AttributeSpec(
            name="name",
            requirement=REQUIRED,
            type="string",
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["tool_call"],
        ),
    }


class OtelGenAIInputMessageToolCallResponsePartSpecification(OtelGenAISpecification):
    """Tool call response input message part specification with required response."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "id": AttributeSpec(
            name="id",
            requirement=OPTIONAL,
            type="string",
        ),
        "response": AttributeSpec(
            name="response",
            requirement=REQUIRED,
            type="any",
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["tool_call_response"],
        ),
    }


class OtelGenAIOutputMessageBlobPartSpecification(OtelGenAISpecification):
    """Blob output message part specification with required content and modality."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "content": AttributeSpec(
            name="content",
            requirement=REQUIRED,
            type="string",
        ),
        "mime_type": AttributeSpec(
            name="mime_type",
            requirement=OPTIONAL,
            type="string",
        ),
        "modality": AttributeSpec(
            name="modality",
            requirement=REQUIRED,
            type="string",
            valid_values=MODALITY_VALUES,
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["blob"],
        ),
    }


class OtelGenAIOutputMessageFilePartSpecification(OtelGenAISpecification):
    """File output message part specification with required file_id and modality."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "file_id": AttributeSpec(
            name="file_id",
            requirement=REQUIRED,
            type="string",
        ),
        "mime_type": AttributeSpec(
            name="mime_type",
            requirement=OPTIONAL,
            type="string",
        ),
        "modality": AttributeSpec(
            name="modality",
            requirement=REQUIRED,
            type="string",
            valid_values=MODALITY_VALUES,
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["file"],
        ),
    }


class OtelGenAIOutputMessageGenericPartSpecification(OtelGenAISpecification):
    """Generic output message part specification with only type validation."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
        ),
    }


class OtelGenAIOutputMessageReasoningPartSpecification(OtelGenAISpecification):
    """Reasoning output message part specification with required content."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "content": AttributeSpec(
            name="content",
            requirement=REQUIRED,
            type="string",
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["reasoning"],
        ),
    }


class OtelGenAIOutputMessageTextPartSpecification(OtelGenAISpecification):
    """Text output message part specification with required content."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "content": AttributeSpec(
            name="content",
            requirement=REQUIRED,
            type="string",
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["text"],
        ),
    }


class OtelGenAIOutputMessageToolCallRequestPartSpecification(OtelGenAISpecification):
    """Tool call request output message part specification with required name."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "arguments": AttributeSpec(
            name="arguments",
            requirement=OPTIONAL,
            type="any",
        ),
        "id": AttributeSpec(
            name="id",
            requirement=OPTIONAL,
            type="string",
        ),
        "name": AttributeSpec(
            name="name",
            requirement=REQUIRED,
            type="string",
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["tool_call"],
        ),
    }


class OtelGenAIOutputMessageToolCallResponsePartSpecification(OtelGenAISpecification):
    """Tool call response output message part specification with required response."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "id": AttributeSpec(
            name="id",
            requirement=OPTIONAL,
            type="string",
        ),
        "response": AttributeSpec(
            name="response",
            requirement=REQUIRED,
            type="any",
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["tool_call_response"],
        ),
    }


class OtelGenAIOutputMessageUriPartSpecification(OtelGenAISpecification):
    """URI output message part specification with required uri and modality."""
    SUPPORTED_ATTRIBUTES: ClassVar[dict[str, AttributeSpec]] = {
        "mime_type": AttributeSpec(
            name="mime_type",
            requirement=OPTIONAL,
            type="string",
        ),
        "modality": AttributeSpec(
            name="modality",
            requirement=REQUIRED,
            type="string",
            valid_values=MODALITY_VALUES,
        ),
        "type": AttributeSpec(
            name="type",
            requirement=REQUIRED,
            type="string",
            valid_values=["uri"],
        ),
        "uri": AttributeSpec(
            name="uri",
            requirement=REQUIRED,
            type="string",
        ),
    }
