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

class ExternalReferenceQueue(Base):
    __tablename__ = "auto_data_crawler_queue"
    __table_args__ = {"schema": "vehicle"}

    id = Column(Integer, primary_key=True, index=True)
    url = Column(String(500), unique=True, nullable=False)
    
    # Szintek: 'brand', 'model', 'generation', 'engine'
    level = Column(String(20), nullable=False, index=True)
    
    # Kategóriák
    category = Column(String(20), default='car', index=True)

    # Szülő azonosító (pl. a modell tudja, melyik márkához tartozik)
    parent_id = Column(Integer, nullable=True)
    
    # Megjelenítési név (pl. "Audi", "A3 Sportback")
    name = Column(String(255))
    
    # Állapot: 'pending', 'processing', 'completed', 'error'
    status = Column(String(20), default='pending', index=True)
    
    # Hibakezeléshez
    error_msg = Column(String(1000), nullable=True)
    retry_count = Column(Integer, default=0)
    
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())