from typing import TYPE_CHECKING

from sqlalchemy import Column, ForeignKey, Integer, String, Enum
from sqlalchemy.orm import relationship

from app.db.base_class import Base


if TYPE_CHECKING:
  from .user import User  # noqa: F401
  from .enum import Progress

class Video(Base):
  id = Column(Integer, primary_key=True, index=True)
  title = Column(String(20), index=True, nullable=False)
  stored_file_name = Column(String(30), unique=True, nullable=False)
  progress_state = Column(String(10), 
                    ForeignKey("progress.state", ondelete="RESTRICT", onupdate="CASCADE"),
                    default="waiting")
  owner_id = Column(Integer, ForeignKey("user.id"))
  owner = relationship("User", back_populates="videos")