|
| 1 | +from typing import TYPE_CHECKING |
| 2 | + |
| 3 | +import requests |
| 4 | + |
| 5 | +from abstract_api.bases import JSONResponse |
| 6 | + |
| 7 | +from .response_fields import RESPONSE_FIELDS |
| 8 | + |
| 9 | + |
| 10 | +class Holiday: |
| 11 | + """Holiday entity in VAT Holidays response.""" |
| 12 | + |
| 13 | + def __init__( |
| 14 | + self, |
| 15 | + name: str, |
| 16 | + name_local: str, |
| 17 | + language: str, |
| 18 | + description: str, |
| 19 | + country: str, |
| 20 | + location: str, |
| 21 | + type: str, |
| 22 | + date: str, |
| 23 | + date_year: str, |
| 24 | + date_month: str, |
| 25 | + date_day: str, |
| 26 | + week_day: str |
| 27 | + ) -> None: |
| 28 | + """Initializes a new Holiday.""" |
| 29 | + self._name = name |
| 30 | + self._name_local = name_local |
| 31 | + self._language = language |
| 32 | + self._description = description |
| 33 | + self._country = country |
| 34 | + self._location = location |
| 35 | + self._type = type |
| 36 | + self._date = date |
| 37 | + self._date_year = date_year |
| 38 | + self._date_month = date_month |
| 39 | + self._date_day = date_day |
| 40 | + self._week_day = week_day |
| 41 | + |
| 42 | + @property |
| 43 | + def name(self) -> str: |
| 44 | + """The name of the holiday.""" |
| 45 | + return self._name |
| 46 | + |
| 47 | + @property |
| 48 | + def name_local(self) -> str: |
| 49 | + """The local name of the holiday.""" |
| 50 | + return self._name_local |
| 51 | + |
| 52 | + @property |
| 53 | + def language(self) -> str: |
| 54 | + """The language in which name_local is in.""" |
| 55 | + return self._language |
| 56 | + |
| 57 | + @property |
| 58 | + def description(self) -> str: |
| 59 | + """A short description or additional details on the holiday. |
| 60 | +
|
| 61 | + Such as the holiday is a part of a long weekend. |
| 62 | + """ |
| 63 | + return self._description |
| 64 | + |
| 65 | + @property |
| 66 | + def country(self) -> str: |
| 67 | + """The country in which the holiday occurs. |
| 68 | +
|
| 69 | + Returned directly from the request. |
| 70 | + """ |
| 71 | + return self._country |
| 72 | + |
| 73 | + @property |
| 74 | + def location(self) -> str: |
| 75 | + """The location or region in which the holiday occurs. |
| 76 | +
|
| 77 | + If the holiday is that specific. |
| 78 | + """ |
| 79 | + return self._location |
| 80 | + |
| 81 | + @property |
| 82 | + def type(self) -> str: |
| 83 | + """The type of holiday it is. |
| 84 | +
|
| 85 | + (e.g., public holiday, religious holiday, etc.). |
| 86 | + """ |
| 87 | + return self._type |
| 88 | + |
| 89 | + @property |
| 90 | + def date(self) -> str: |
| 91 | + """The date on which the holiday occurs.""" |
| 92 | + return self._date |
| 93 | + |
| 94 | + @property |
| 95 | + def date_year(self) -> str: |
| 96 | + """The year in which the holiday occurs.""" |
| 97 | + return self._date_year |
| 98 | + |
| 99 | + @property |
| 100 | + def date_month(self) -> str: |
| 101 | + """The month in which the holiday occurs.""" |
| 102 | + return self._date_month |
| 103 | + |
| 104 | + @property |
| 105 | + def date_day(self) -> str: |
| 106 | + """The day in which the holiday occurs.""" |
| 107 | + return self._date_day |
| 108 | + |
| 109 | + @property |
| 110 | + def week_day(self) -> str: |
| 111 | + """The day of the week on which the holiday occurs. |
| 112 | +
|
| 113 | + (Monday, Tuesday, Wednesday, etc.). |
| 114 | + """ |
| 115 | + return self._week_day |
| 116 | + |
| 117 | + |
| 118 | +class HolidaysResponse(JSONResponse): |
| 119 | + """Holidays service response.""" |
| 120 | + |
| 121 | + def __init__(self, response: requests.models.Response) -> None: |
| 122 | + """Initializes a new VATValidationResponse.""" |
| 123 | + super().__init__(response) |
| 124 | + self._response_fields = RESPONSE_FIELDS |
| 125 | + |
| 126 | + if self.meta.body_json is not None: |
| 127 | + holidays = [] |
| 128 | + for c in self.meta.body_json: |
| 129 | + if TYPE_CHECKING: |
| 130 | + assert isinstance(c, dict) |
| 131 | + holidays.append(Holiday(**c)) |
| 132 | + self._holidays = frozenset(holidays) |
| 133 | + |
| 134 | + @property |
| 135 | + def holidays(self) -> frozenset[Holiday]: |
| 136 | + """The returned holidays.""" |
| 137 | + return self._get_response_field("holidays") |
0 commit comments