from datetime import datetime

from src.db.models.media import MediaFile
from pydantic import BaseModel


class MediaFileResponse(BaseModel):
    id: str
    title: str | None = None
    file_name: str | None = None
    cloud_link: str | None = None
    url: str | None = None
    review: bool = False
    should_download: bool = False

class Link(BaseModel):
    url: str

def get_file_details(mediafile: MediaFile) -> MediaFileResponse:
    response = MediaFileResponse(id=mediafile.id,
                                 title=mediafile.title,
                                 file_name=mediafile.file_name,
                                 cloud_link=mediafile.cloud_link,
                                 url=str(mediafile.url),
                                 review=mediafile.review,
                                 should_download=mediafile.should_download)
    #print(f"id: {mediafile.id}: review: {response.review} <- {mediafile.review}")
    #print(f"id: {mediafile.id}: download: {response.should_download} <- {mediafile.should_download}")
    return response

def set_file(model: MediaFileResponse, mediafile: MediaFile) -> None:
    mediafile.file_name = model.file_name
    mediafile.cloud_link = model.cloud_link # type: ignore
    mediafile.url = model.url # type: ignore
    mediafile.title = model.title
    mediafile.last_modified_date = datetime.now()
    mediafile.review = model.review
    mediafile.should_download = model.should_download
