"""Video Type model.""" from typing import Any from sqlalchemy import Column, Enum, select from sqlalchemy.dialects.mysql import INTEGER, VARCHAR from sqlalchemy.orm import Mapped, mapped_column from video.connectors import mysql class VideoType(mysql.BaseModel): """Video Type model.""" __tablename__ = "video_type" video_type_id = Column( INTEGER, nullable=False, primary_key=True, autoincrement=True, ) video_type = Column(VARCHAR(length=256)) video_asset_type: Mapped[str | None] = mapped_column( Enum("Music Video", "Web Video"), name="video_asset_type", ) def to_dict(self) -> dict[str, Any]: """Get a dict representation.""" return { "video_type_id": self.video_type_id, "video_type": self.video_type, "video_asset_type": self.video_asset_type, } def get_video_type(video_type: str) -> dict[str, Any]: """Get the video type details. Returns: dict: video type data. Returns empty dict if not found. """ with mysql.db_session() as session: result = session.execute( select(VideoType).where(VideoType.video_type == video_type) ).scalar_one_or_none() if not result: return {} return result.to_dict() def get_all() -> list[dict[str, Any]]: """Get all video types.""" with mysql.db_session() as session: video_types = session.execute(select(VideoType)).scalars().all() return [item.to_dict() for item in video_types]