import enum
from sqlalchemy import Column, Integer, String, ForeignKey, Enum, DateTime, Boolean, Text
from sqlalchemy.orm import relationship
from app.core.database import Base
from datetime import datetime

# Enums
class ModerationStatus(str, enum.Enum):
    pending = "pending"
    approved = "approved"
    rejected = "rejected"

class SourceType(str, enum.Enum):
    manual = "manual"
    ocr = "ocr"
    api_import = "import"

class ServiceProvider(Base):
    __tablename__ = "service_providers"
    __table_args__ = {"schema": "data"}

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String, nullable=False)
    address = Column(String, nullable=False)
    category = Column(String) 
    
    # --- JAVÍTÁS ITT: schema="data" hozzáadása ---
    # Megmondjuk, hogy az Enum típus a 'data' sémába kerüljön
    status = Column(Enum(ModerationStatus, schema="data", name="moderation_status_enum"), default=ModerationStatus.pending, nullable=False)
    source = Column(Enum(SourceType, schema="data", name="source_type_enum"), default=SourceType.manual, nullable=False)
    # ---------------------------------------------
    
    evidence_image_path = Column(String, nullable=True)
    
    added_by_user_id = Column(Integer, ForeignKey("data.users.id"))
    created_at = Column(DateTime, default=datetime.utcnow)

class Competition(Base):
    __tablename__ = "competitions"
    __table_args__ = {"schema": "data"}

    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)
    description = Column(Text)
    start_date = Column(DateTime, nullable=False)
    end_date = Column(DateTime, nullable=False)
    is_active = Column(Boolean, default=True)

class UserScore(Base):
    __tablename__ = "user_scores"
    __table_args__ = {"schema": "data"}

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey("data.users.id"))
    competition_id = Column(Integer, ForeignKey("data.competitions.id"))
    points = Column(Integer, default=0)
    last_updated = Column(DateTime, default=datetime.utcnow)