from typing import Optional


class TimeZoneJsonData:
    def __init__(self, ctm_code: str, id: str, code: str, name: str, offset_sign: str, offset_hour: str,
                 offset_minute: str,
                 has_dst: bool, show_ui: bool, dst_from_year: Optional[str] = None,
                 dst_from_month: Optional[str] = None,
                 dst_from_day: Optional[str] = None, dst_from_hour: Optional[str] = None,
                 dst_from_minute: Optional[str] = None,
                 dst_to_year: Optional[str] = None, dst_to_month: Optional[str] = None,
                 dst_to_day: Optional[str] = None,
                 dst_to_hour: Optional[str] = None, dst_to_minute: Optional[str] = None,
                 dst_offset_sign: Optional[str] = None,
                 dst_offset_hour: Optional[str] = None, dst_offset_minute: Optional[str] = None,
                 dst_gmt_offset_sign: Optional[str] = None,
                 dst_gmt_offset_hour: Optional[str] = None, dst_gmt_offset_minute: Optional[str] = None,
                 ui_name: Optional[str] = None):
        self.ctm_code = ctm_code
        self.id = id
        self.code = code
        self.name = name
        self.offset_sign = offset_sign
        self.offset_hour = offset_hour
        self.offset_minute = offset_minute
        self.has_dst = has_dst
        self.show_ui = show_ui
        self.dst_from_year = dst_from_year
        self.dst_from_month = dst_from_month
        self.dst_from_day = dst_from_day
        self.dst_from_hour = dst_from_hour
        self.dst_from_minute = dst_from_minute
        self.dst_to_year = dst_to_year
        self.dst_to_month = dst_to_month
        self.dst_to_day = dst_to_day
        self.dst_to_hour = dst_to_hour
        self.dst_to_minute = dst_to_minute
        self.dst_offset_sign = dst_offset_sign
        self.dst_offset_hour = dst_offset_hour
        self.dst_offset_minute = dst_offset_minute
        self.dst_gmt_offset_sign = dst_gmt_offset_sign
        self.dst_gmt_offset_hour = dst_gmt_offset_hour
        self.dst_gmt_offset_minute = dst_gmt_offset_minute
        self.ui_name = ui_name


    def is_matching_gmt(self, hour, minute, sign):
        return hour == self.offset_hour and minute == self.offset_minute and sign == self.offset_sign

    #translating from members to json attributes whichare upper case and contain '_' instead of '-'
    #Example dst_from_day ->DST-FROM-DAY
    def to_dict(self):
        return {key: value for key, value in{
            key.upper().replace('_', '-'): value
            for key, value in self.__dict__.items()
        }.items() if value is not None}  # if filed is value ot os not serialized to file

