8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165 | class ModelExecutionConfigBuilder:
"""
Builder base para configuração da execução dos modelos.
O SDK usa esta abstração para esconder os cards do `entrada.txt`
e permitir que o consumidor configure a intenção de uso de forma direta.
"""
def __init__(self) -> None:
self._executa_newave: bool | None = None
self._versao_newave: str | None = None
self._executa_gevazp: bool | None = None
self._versao_gevazp: str | None = None
self._executa_decomp: bool | None = None
self._versao_decomp: str | None = None
self._executa_dessem: bool | None = None
self._revisao_parada: int | None = None
self._viabiliza_decomp: bool | None = None
self._numero_tentativas_viabiliza_decomp: int | None = None
def set_newave(
self,
enabled: bool | None = None,
version: str | None = None,
) -> "ModelExecutionConfigBuilder":
if enabled is None and version is None:
raise ValueError("Informe enabled e/ou version para o NEWAVE.")
if enabled is not None and not isinstance(enabled, bool):
raise ValueError("newave.enabled deve ser boolean.")
self._executa_newave = enabled if enabled is not None else self._executa_newave
self._versao_newave = (
self._normalize_version(version, "newave.version")
if version is not None
else self._versao_newave
)
return self
def set_gevazp(
self,
enabled: bool | None = None,
version: str | None = None,
) -> "ModelExecutionConfigBuilder":
if enabled is None and version is None:
raise ValueError("Informe enabled e/ou version para o GEVAZP.")
if enabled is not None and not isinstance(enabled, bool):
raise ValueError("gevazp.enabled deve ser boolean.")
self._executa_gevazp = enabled if enabled is not None else self._executa_gevazp
self._versao_gevazp = (
self._normalize_version(version, "gevazp.version")
if version is not None
else self._versao_gevazp
)
return self
def set_decomp(
self,
enabled: bool | None = None,
version: str | None = None,
) -> "ModelExecutionConfigBuilder":
if enabled is None and version is None:
raise ValueError("Informe enabled e/ou version para o DECOMP.")
if enabled is not None and not isinstance(enabled, bool):
raise ValueError("decomp.enabled deve ser boolean.")
self._executa_decomp = enabled if enabled is not None else self._executa_decomp
self._versao_decomp = (
self._normalize_version(version, "decomp.version")
if version is not None
else self._versao_decomp
)
return self
def set_dessem(self, enabled: bool) -> "ModelExecutionConfigBuilder":
if not isinstance(enabled, bool):
raise ValueError("dessem.enabled deve ser boolean.")
self._executa_dessem = enabled
return self
def set_stop_revision(self, revision: int) -> "ModelExecutionConfigBuilder":
if not isinstance(revision, int) or isinstance(revision, bool):
raise ValueError("stop_revision deve ser inteiro.")
if revision < 0 or revision > 9:
raise ValueError("stop_revision deve estar entre 0 e 9.")
self._revisao_parada = revision
return self
def set_decomp_viabilization(
self,
enabled: bool | None = None,
max_attempts: int | None = None,
) -> "ModelExecutionConfigBuilder":
if enabled is None and max_attempts is None:
raise ValueError("Informe enabled e/ou max_attempts para a viabilização do DECOMP.")
if enabled is not None and not isinstance(enabled, bool):
raise ValueError("decomp_viabilization.enabled deve ser boolean.")
if max_attempts is not None:
if not isinstance(max_attempts, int) or isinstance(max_attempts, bool):
raise ValueError("decomp_viabilization.max_attempts deve ser inteiro.")
if max_attempts < 1 or max_attempts > 9:
raise ValueError("decomp_viabilization.max_attempts deve estar entre 1 e 9.")
self._viabiliza_decomp = enabled if enabled is not None else self._viabiliza_decomp
self._numero_tentativas_viabiliza_decomp = (
max_attempts
if max_attempts is not None
else self._numero_tentativas_viabiliza_decomp
)
return self
def build(self) -> ConfiguracaoExecucaoModelosRequest:
if not self._has_any_value():
raise ValueError("Informe ao menos uma configuraçãoo de execução dos modelos.")
return ConfiguracaoExecucaoModelosRequest(
executaNewave=self._executa_newave,
versaoNewave=self._versao_newave,
executaGevazp=self._executa_gevazp,
versaoGevazp=self._versao_gevazp,
executaDecomp=self._executa_decomp,
versaoDecomp=self._versao_decomp,
executaDessem=self._executa_dessem,
revisaoParada=self._revisao_parada,
viabilizaDecomp=self._viabiliza_decomp,
numeroTentativasViabilizaDecomp=self._numero_tentativas_viabiliza_decomp,
)
def _has_any_value(self) -> bool:
return any(
value is not None
for value in (
self._executa_newave,
self._versao_newave,
self._executa_gevazp,
self._versao_gevazp,
self._executa_decomp,
self._versao_decomp,
self._executa_dessem,
self._revisao_parada,
self._viabiliza_decomp,
self._numero_tentativas_viabiliza_decomp,
)
)
def _normalize_version(self, version: str, field_name: str) -> str:
normalized = str(version).strip()
if not normalized:
raise ValueError(f"{field_name} deve ser informado sem espaços em branco.")
return normalized
|