# -*- coding: utf-8 -*-
# hub/ticket/domain/ticket_types.py

"""Базовые доменные типы Ticket без зависимости от legacy GUI."""

from __future__ import annotations

from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum
from typing import Mapping


class TicketConnectionStatus(str, Enum):
    """Нормализованный статус аппаратного подключения Ticket."""

    CONNECTED = "connected"
    DISCONNECTED = "disconnected"
    ERROR = "error"


@dataclass(frozen=True, slots=True)
class TicketTaskSnapshot:
    """Плоский снимок задачи для обмена между слоями."""

    task_id: int
    location: str
    state_code: int
    state_name: str
    action_text: str = ""
    color_hex: str = "#FFFFFF"
    created_at: datetime | None = None
    completed_at: datetime | None = None
    refused_from_state: int | None = None
    refusal_reason: str = ""
    assigned_specialist: str = ""
    specialist_photo: str = ""
    diagnostic_report_signed: bool = False
    repair_report_signed: bool = False
    acceptance_report_signed: bool = False
    sequence_number: int = 0


@dataclass(frozen=True, slots=True)
class TicketDocumentSnapshot:
    """Плоский снимок сохранённого документа Ticket."""

    document_id: str
    task_id: int
    document_type: str
    title: str
    created_at: datetime
    location: str = ""
    specialist_name: str = ""
    summary: str = ""
    content: str = ""
    storage_path: str = ""
    payload: Mapping[str, str] = field(default_factory=dict)


@dataclass(frozen=True, slots=True)
class TicketHardwareStatus:
    """Снимок статуса аппаратного шлюза."""

    connection_status: TicketConnectionStatus = TicketConnectionStatus.DISCONNECTED
    message: str = ""
    buttons_initialized: bool = False
    button_count: int = 0


@dataclass(frozen=True, slots=True)
class ArchiveRecordSnapshot:
    """Плоский снимок архивной записи по завершённой или отказной задаче."""

    task_id: int
    location: str
    pre_archive_state_code: int
    pre_archive_state_name: str
    color_hex: str = "#FFFFFF"
    created_at: datetime | None = None
    completed_at: datetime | None = None
    archived_at: datetime | None = None
    refused_from_state: int | None = None
    refusal_reason: str = ""
    assigned_specialist: str = ""
    specialist_photo: str = ""
    diagnostic_report_signed: bool = False
    repair_report_signed: bool = False
    acceptance_report_signed: bool = False
    document_ids: tuple[str, ...] = ()
    action_text: str = ""
    sequence_number: int = 0
