from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, func
from app.database import Base


class InspectionLocation(Base):
    __tablename__ = "inspection_locations"

    id = Column(Integer, primary_key=True, index=True)
    code = Column(String(30), unique=True, nullable=False, index=True)
    name = Column(String(100), nullable=False)
    description = Column(Text)
    sort_order = Column(Integer, default=0)
    created_at = Column(DateTime, server_default=func.now())


class InspectionRecord(Base):
    __tablename__ = "inspection_records"

    id = Column(Integer, primary_key=True, index=True)
    location_id = Column(Integer, ForeignKey("inspection_locations.id"), nullable=False)
    location_name = Column(String(100))
    equipment_code = Column(String(30), index=True)
    equipment_name = Column(String(100))
    scan_code = Column(String(200))
    inspector = Column(String(50), nullable=False)
    result = Column(String(20), default="normal")
    notes = Column(Text)
    created_at = Column(DateTime, server_default=func.now())
