from datetime import datetime
from sqlalchemy import String, ForeignKey, Integer, DateTime
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.core.database import Base


class AssignmentProof(Base):
    """Файлы-доказательства для заданий (множественные пруфы)"""
    __tablename__ = "assignment_proofs"

    id: Mapped[int] = mapped_column(primary_key=True)
    assignment_id: Mapped[int] = mapped_column(
        ForeignKey("assignments.id", ondelete="CASCADE"),
        index=True
    )
    file_path: Mapped[str] = mapped_column(String(500))  # Путь к файлу в хранилище
    file_type: Mapped[str] = mapped_column(String(20))  # image или video
    order_index: Mapped[int] = mapped_column(Integer, default=0)  # Порядок отображения
    created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)

    # Relationships
    assignment: Mapped["Assignment"] = relationship(
        "Assignment",
        back_populates="proof_files"
    )


class BonusAssignmentProof(Base):
    """Файлы-доказательства для бонусных заданий (множественные пруфы)"""
    __tablename__ = "bonus_assignment_proofs"

    id: Mapped[int] = mapped_column(primary_key=True)
    bonus_assignment_id: Mapped[int] = mapped_column(
        ForeignKey("bonus_assignments.id", ondelete="CASCADE"),
        index=True
    )
    file_path: Mapped[str] = mapped_column(String(500))  # Путь к файлу в хранилище
    file_type: Mapped[str] = mapped_column(String(20))  # image или video
    order_index: Mapped[int] = mapped_column(Integer, default=0)  # Порядок отображения
    created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)

    # Relationships
    bonus_assignment: Mapped["BonusAssignment"] = relationship(
        "BonusAssignment",
        back_populates="proof_files"
    )
