from msgbus import MBEasyContext
from old_helper import BaseRepository
from typing import List


class UserRepository(BaseRepository):
    def __init__(
            self,
            mb_context  # type: MBEasyContext
    ):

        super(UserRepository, self).__init__(mb_context)

    def get_own_delivery_men(
            self
    ):
        # type: (...) -> List

        def inner_func(conn):

            couriers = []
            query = "SELECT UserId, LongName FROM Users WHERE Level = -1"
            cursor = conn.select(query)
            if cursor.rows() > 0:
                for row in cursor:
                    couriers.append({'userId': row.get_entry("UserId"), 'name': row.get_entry("LongName")})

            return couriers

        return self.execute_with_connection(inner_func)
