from sqlalchemy import ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from app.core.database import Base from app.models.attachment_point_name import AttachmentPointName from app.models.clamp_connection import ClampConnection from app.models.iso_thread import IsoThread from app.models.static_connection import StaticConnection from app.models.unc_thread import UncThread class AttachmentPoint(Base): __tablename__ = "attachment_points" id: Mapped[int] = mapped_column(primary_key=True) augmented_part_id: Mapped[int] = mapped_column( ForeignKey("augmented_parts.id", ondelete="CASCADE"), nullable=False ) attachment_point_name_id: Mapped[int] = mapped_column( ForeignKey("attachment_point_names.id", ondelete="RESTRICT"), nullable=False ) # At most one of the four below is non-null (enforced in application layer). # All four null means a "Manual" attachment point: no connection details, # used to let a user assert a Fit by hand without the fit-matching algorithm # (app.services.fit_matching) ever auto-matching it. iso_thread_id: Mapped[int | None] = mapped_column( ForeignKey("iso_threads.id", ondelete="RESTRICT"), nullable=True, default=None ) unc_thread_id: Mapped[int | None] = mapped_column( ForeignKey("unc_threads.id", ondelete="RESTRICT"), nullable=True, default=None ) clamp_connection_id: Mapped[int | None] = mapped_column( ForeignKey("clamp_connections.id", ondelete="RESTRICT"), nullable=True, default=None, ) static_connection_id: Mapped[int | None] = mapped_column( ForeignKey("static_connections.id", ondelete="RESTRICT"), nullable=True, default=None, ) attachment_point_name: Mapped[AttachmentPointName] = relationship(lazy="selectin") iso_thread: Mapped[IsoThread | None] = relationship(lazy="selectin") unc_thread: Mapped[UncThread | None] = relationship(lazy="selectin") clamp_connection: Mapped[ClampConnection | None] = relationship(lazy="selectin") static_connection: Mapped[StaticConnection | None] = relationship(lazy="selectin")