from __future__ import annotations

import enum
from datetime import date

from sqlalchemy import Date, Enum, String
from sqlalchemy.orm import Mapped, mapped_column

from app.db.base import Base, TimestampMixin, UUIDMixin


class EquipmentKind(str, enum.Enum):
    temperature_logger = "temperature_logger"
    pressure_logger = "pressure_logger"
    sensor = "sensor"


class EquipmentStatus(str, enum.Enum):
    green = "green"
    yellow = "yellow"
    red = "red"


class Equipment(Base, UUIDMixin, TimestampMixin):
    __tablename__ = "equipment"

    kind: Mapped[EquipmentKind] = mapped_column(Enum(EquipmentKind))
    manufacturer: Mapped[str | None] = mapped_column(String(140))
    model: Mapped[str | None] = mapped_column(String(140))
    serial_number: Mapped[str] = mapped_column(String(140), unique=True, index=True)
    calibrated_on: Mapped[date | None] = mapped_column(Date)
    calibration_due_on: Mapped[date | None] = mapped_column(Date)
    certificate_document_id: Mapped[str | None] = mapped_column(String(80))
    status: Mapped[EquipmentStatus] = mapped_column(Enum(EquipmentStatus), default=EquipmentStatus.green)
    notes: Mapped[str | None] = mapped_column(String(500))
