# /opt/docker/dev/service_finder/backend/app/models/vehicle/external_reference.py
from sqlalchemy import Column, Integer, String, JSON, DateTime, UniqueConstraint, ForeignKey
from sqlalchemy.sql import func
from app.database import Base

class ExternalReferenceLibrary(Base):
    __tablename__ = "external_reference_library"
    __table_args__ = (
        UniqueConstraint('source_url', name='_source_url_uc'),
        {"schema": "vehicle"}
    )

    id = Column(Integer, primary_key=True, index=True)
    source_name = Column(String(50), default="auto-data.net") # Később jöhet más forrás is (motorokhoz/kamionokhoz)
    make = Column(String(100), index=True)
    model = Column(String(100), index=True)
    generation = Column(String(255))
    modification = Column(String(255))
    year_from = Column(Integer)
    year_to = Column(Integer, nullable=True)
    power_kw = Column(Integer, index=True)
    engine_cc = Column(Integer, index=True)
    category = Column(String(20), default='car', index=True) # ÚJ
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    
    # Minden egyéb technikai adat (olaj, gumi, fogyasztás stb.) ide megy
    specifications = Column(JSON, default={})
    
    source_url = Column(String(500), unique=True)
    last_scraped_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
    
    pipeline_status = Column(String(30), default='pending_enrich', index=True)
    matched_vmd_id = Column(Integer, ForeignKey('vehicle.vehicle_model_definitions.id'), nullable=True, index=True)

    # Biztosítjuk, hogy ne legyen duplikáció azonos linkről
    