# /opt/docker/dev/service_finder/backend/app/models/system/legal.py
from datetime import datetime
from typing import Optional
from sqlalchemy import Integer, String, Text, DateTime, ForeignKey, Boolean
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import func
from app.db.base_class import Base

class LegalDocument(Base):
    __tablename__ = "legal_documents"
    __table_args__ = {"schema": "system"}

    id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
    title: Mapped[Optional[str]] = mapped_column(String(255))
    content: Mapped[str] = mapped_column(Text)
    version: Mapped[str] = mapped_column(String(20))
    
    region_code: Mapped[str] = mapped_column(String(5), default="HU")
    language: Mapped[str] = mapped_column(String(5), default="hu")
    
    is_active: Mapped[bool] = mapped_column(Boolean, default=True)
    created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())

class LegalAcceptance(Base):
    __tablename__ = "legal_acceptances"
    __table_args__ = {"schema": "identity"}

    id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
    user_id: Mapped[int] = mapped_column(Integer, ForeignKey("identity.users.id"))
    document_id: Mapped[int] = mapped_column(Integer, ForeignKey("system.legal_documents.id"))
    accepted_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
    ip_address: Mapped[Optional[str]] = mapped_column(String(45))
    user_agent: Mapped[Optional[str]] = mapped_column(Text)