from typing import Union
from uuid import uuid4

import inject
from sqlmodel import Session, select

from src.core.events import EventDescription
from src.core.models import Context, File
from src.core.services import Storage, Streamer
from src.utils.miscellaneous import get_file_hash


@inject.params(streamer=Streamer, storage=Storage)
def get_or_create_file(
    session: Session,
    preffix: str,
    filename: str,
    file: Union[str, bytes],
    context: Context,
    streamer: Streamer,
    storage: Storage,
) -> File:
    file_hash = get_file_hash(file)
    file_obj = session.exec(