from sqlalchemy import ForeignKey, String from sqlalchemy.orm import Mapped, mapped_column, relationship from app.core.database import Base from app.models.associations import augmented_part_imported_parts from app.models.imported_part import ImportedPart from app.models.manufacturer import Manufacturer from app.models.part_colour import PartColour from app.models.part_type import PartType from app.models.scope_model import ScopeModel from app.models.sub_part_type import SubPartType class AugmentedPart(Base): __tablename__ = "augmented_parts" id: Mapped[int] = mapped_column(primary_key=True) sku: Mapped[str | None] = mapped_column(String, nullable=True, default=None) description: Mapped[str] = mapped_column(String, nullable=False) colour_id: Mapped[int] = mapped_column( ForeignKey("part_colours.id", ondelete="RESTRICT"), nullable=False ) manufacturer_id: Mapped[int] = mapped_column( ForeignKey("manufacturers.id", ondelete="RESTRICT"), nullable=False ) scope_model_id: Mapped[int | None] = mapped_column( ForeignKey("scope_models.id", ondelete="SET NULL"), nullable=True, default=None ) part_type_id: Mapped[int] = mapped_column( ForeignKey("part_types.id", ondelete="RESTRICT"), nullable=False ) sub_part_type_id: Mapped[int | None] = mapped_column( ForeignKey("sub_part_types.id", ondelete="SET NULL"), nullable=True, default=None ) # linked imported parts — not eagerly loaded; used by sync service only imported_parts: Mapped[list[ImportedPart]] = relationship( secondary=augmented_part_imported_parts, lazy="select" ) colour: Mapped[PartColour] = relationship(lazy="selectin") manufacturer: Mapped[Manufacturer] = relationship(lazy="selectin") scope_model: Mapped[ScopeModel | None] = relationship(lazy="selectin") part_type: Mapped[PartType] = relationship(lazy="selectin") sub_part_type: Mapped[SubPartType | None] = relationship(lazy="selectin")