from typing import List
from uuid import UUID

import inject
from sqlalchemy.sql.expression import desc
from sqlmodel import Session, between, select

from src.core.events import EventDescription
from src.core.helpers.exceptions import DataValidationError, NotAuthorizedError, NotFoundError
from src.core.models import (
    Client,
    Context,
    CreateBalance,
    CreateOrder,
    Item,
    Order,
    OrderDetail,
    QueryOrder,
    UpdateOrder,
    UpdateOrderStatus,
)
from src.core.services import Streamer

from . import balance


def get_all(session: Session, query_schema: QueryOrder, context: Context) -> List[Order]:
    args = []

    if query_schema.status is not None:
        args.append(Order.status == query_schema.status)

    if not context.user_is_super_user:
        args.append(Order.owner_id == context.user_id)

    if query_schema.start_date is not None and query_schema.end_date is not None:
        args.append(between(Order.date, query_schema.start_date, query_schema.end_date))

    return session.exec(