from old_helper import BaseRepository
from typing import List


class ServicePeriodRepository(BaseRepository):
    def __init__(self, mb_context):
        super(ServicePeriodRepository, self).__init__(mb_context)

    def get_services_period(self):
        # type: () -> List

        def inner_func(conn):
            services = []
            cursor = conn.select(self._get_service_periods_query)
            if cursor.rows() > 0:
                for row in cursor:
                    data = {'id': row.get_entry("ServicePeriodId"),
                            'name': row.get_entry("Name"),
                            'startHour':  row.get_entry("StartHour"),
                            'endHour': row.get_entry("EndHour"),
                            'weekDays': row.get_entry("WeekDays"),
                            'priceListId': row.get_entry("PriceListId"),
                            'priceListAbbr': row.get_entry("Abbreviation") or ""
                            }
                    services.append(data)

            return services

        return self.execute_with_connection(inner_func)

    _get_service_periods_query = \
        """SELECT * 
             FROM ServicePeriod s"""
