"""Connector DTOs — Phase 12.7."""
from __future__ import annotations

from datetime import datetime
from uuid import UUID

from pydantic import BaseModel, Field

from app.models.types import (
    ConnectorKind,
    ConnectorStatus,
    DispatchDirection,
    DispatchStatus,
)
from app.schemas.common import ORMBase


class ConnectorRegistrationCreate(BaseModel):
    venue_id: UUID | None = None
    kind: ConnectorKind
    code: str = Field(max_length=50)
    name: str = Field(max_length=255)
    status: ConnectorStatus = ConnectorStatus.DRAFT
    external_ref: str | None = None
    config: dict | None = None


class ConnectorRegistrationRead(ORMBase):
    id: UUID
    tenant_id: UUID
    venue_id: UUID | None
    kind: ConnectorKind
    code: str
    name: str
    status: ConnectorStatus
    external_ref: str | None
    config: dict | None
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime


class ConnectorDispatchCreate(BaseModel):
    venue_id: UUID | None = None
    registration_id: UUID
    direction: DispatchDirection = DispatchDirection.OUTBOUND
    event_type: str = Field(max_length=100)
    payload_ref: str | None = None


class ConnectorDispatchRead(ORMBase):
    id: UUID
    tenant_id: UUID
    venue_id: UUID | None
    registration_id: UUID
    direction: DispatchDirection
    event_type: str
    payload_ref: str | None
    status: DispatchStatus
    response_json: dict | None
    notes: str | None
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime
