
from typing import List

from fastapi import APIRouter, HTTPException

from src.db.models.media import MediaVideo
from src.db.session import SessionDep
from src.schema.media.video import MediaVideoResponse, video_to_response


router = APIRouter()

@router.get("/videos", response_model=List[MediaVideoResponse])
def get_all_videos(
    db: SessionDep, review: bool = False, download: bool = False
) -> List[MediaVideoResponse]:
    """
    Get all MediaVideos.
    """
    results: List[MediaVideoResponse] = []
    files: List[MediaVideo]
    if review:
        files = db.query(MediaVideo).filter(MediaVideo.review.is_(True)).all()
    elif download:
        files = db.query(MediaVideo).filter(MediaVideo.should_download.is_(True)).all()
    else:
        files = db.query(MediaVideo).all()
    for mediafile in files:
        response = video_to_response(mediafile)
        results.append(response)
    return results

@router.get("/videos/{video_id}", response_model=MediaVideoResponse)
def get_video(video_id: str, db: SessionDep) -> MediaVideoResponse:
    """
    Get MediaVideo by id.
    """
    video = db.get(MediaVideo, video_id)
    if video is None:
        raise HTTPException(status_code=404, detail="MediaVideo could not be found")
    response = video_to_response(video)
    return response
