from datetime import datetime
import uuid

from sqlalchemy.orm import Session

from src.core.log_conf import logger
from src.db.models.media import MediaActorFile
from src.schema.media.actor import MediaActorModel
from src.schema.media.actorfile import MediaActorFileModel


def create_new_mediaactorfile(db: Session, actor_id: str, file_id: str) -> MediaActorFile:
    logger.info(f"create MediaActorFile with actor {actor_id} and file {file_id}")
    media_actor_file: MediaActorFile = MediaActorFile()
    media_actor_file.id = str(uuid.uuid4())
    media_actor_file.created_date = datetime.now()
    media_actor_file.last_modified_date = datetime.now()
    media_actor_file.version = 0
    media_actor_file.media_actor_id = actor_id
    media_actor_file.media_file_id = file_id
    db.add(media_actor_file)
    db.commit()
    db.refresh(media_actor_file)
    return media_actor_file

def delete_mediaactorfile(db: Session, actorfile_id: str):
    logger.info(f"delete MediaActorFile with id {actorfile_id}")
    media_actorfile = db.get(MediaActorFile, actorfile_id)
    db.delete(media_actorfile)
    db.commit()

def import_mediaactorfile(db: Session, new_actorfile: MediaActorFileModel) -> MediaActorFile:
    """
    Import MediaFile and set missing values with default ones.
    """
    logger.info("import MediaActorFile with %s", new_actorfile)
    media_actor_file: MediaActorFile = MediaActorFile()
    return media_actor_file
    