linting ...
[oam.git] / code / network-generator / network_generation / model / python / top.py
1 # Copyright 2023 highstreet technologies GmbH
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # !/usr/bin/python
16
17 """
18 An abstract Class for all classes
19 """
20 from abc import ABC, abstractmethod
21 from typing import Any, TypedDict, cast
22
23 from network_generation.model.python.type_definitions import (
24     AdministrativeState,
25     AlarmState,
26     LifeCycleState,
27     OperationalState,
28     UsageState,
29     Utilization,
30 )
31
32
33 # Define the ITop interface
34 class ITop(TypedDict):
35     id: str
36     name: str
37     administrativeState: AdministrativeState
38     operationalState: OperationalState
39     lifeCycleState: LifeCycleState
40     alarmState: AlarmState
41     usageState: UsageState
42     utilization: Utilization
43
44
45 # define default value
46 default_value: ITop = {
47     "id": "be5229af-2660-4bae-8f2c-b9d0f788fad1",
48     "name": "NoName",
49     "administrativeState": AdministrativeState.LOCKED,
50     "operationalState": OperationalState.DISABLED,
51     "lifeCycleState": LifeCycleState.PLANNED,
52     "alarmState": 0,
53     "usageState": UsageState.UNUSED,
54     "utilization": 0,
55 }
56
57
58 # Define the Top class
59 class Top(ABC):
60     @staticmethod
61     def default() -> dict[str, Any]:
62         return cast(dict[str, Any], default_value)
63
64     def __init__(
65         self, data: dict[str, Any] = cast(dict[str, Any], default_value)
66     ) -> None:
67         super().__init__()
68         itop: ITop = self._to_itop_data(data)
69         self._id: str = itop["id"]
70         self._name: str = itop["name"]
71         self._administrativeState: AdministrativeState = itop[
72             "administrativeState"
73         ]
74         self._operationalState: OperationalState = itop["operationalState"]
75         self._lifeCycleState: LifeCycleState = itop["lifeCycleState"]
76         self._alarmState: AlarmState = itop["alarmState"]
77         self._usageState: UsageState = itop["usageState"]
78         self._utilization: Utilization = itop["utilization"]
79
80     def _to_itop_data(self, data: dict[str, Any]) -> ITop:
81         result: ITop = default_value
82         for key, key_type in ITop.__annotations__.items():
83             if key in data:
84                 result[key] = data[key]  # type: ignore
85         return result
86
87     @property
88     def id(self) -> str:
89         return self._id
90
91     @id.setter
92     def id(self, value: str) -> None:
93         self._id = value
94
95     @property
96     def name(self) -> str:
97         return self._name
98
99     @name.setter
100     def name(self, value: str) -> None:
101         self._name = value
102
103     @property
104     def administrativeState(self) -> AdministrativeState:
105         return self._administrativeState
106
107     @administrativeState.setter
108     def administrativeState(self, value: AdministrativeState) -> None:
109         self._administrativeState = value
110
111     @property
112     def operationalState(self) -> OperationalState:
113         return self._operationalState
114
115     @operationalState.setter
116     def operationalState(self, value: OperationalState) -> None:
117         self._operationalState = value
118
119     @property
120     def lifeCycleState(self) -> LifeCycleState:
121         return self._lifeCycleState
122
123     @lifeCycleState.setter
124     def lifeCycleState(self, value: LifeCycleState) -> None:
125         self._lifeCycleState = value
126
127     @property
128     def alarmState(self) -> AlarmState:
129         return self._alarmState
130
131     @alarmState.setter
132     def alarmState(self, value: AlarmState) -> None:
133         self._alarmState = value
134
135     @property
136     def usageState(self) -> UsageState:
137         return self._usageState
138
139     @usageState.setter
140     def usageState(self, value: UsageState) -> None:
141         self._usageState = value
142
143     @property
144     def utilization(self) -> Utilization:
145         return self._utilization
146
147     @utilization.setter
148     def utilization(self, value: Utilization) -> None:
149         self._utilization = value
150
151     @abstractmethod
152     def json(self) -> dict[str, Any]:
153         return {
154             "id": self.id,
155             "name": self.name,
156             "administrativeState": self.administrativeState,
157             "operationalState": self.operationalState,
158             "lifeCycleState": self.lifeCycleState,
159             "alarmState": self.alarmState,
160             "usageState": self.usageState,
161             "utilization": self.utilization,
162         }
163
164     def __str__(self) -> str:
165         return str(self.json())