Builder base para configuração de execução com partida.
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.
Source code in pldpro_sdk/models/execution_with_partida.py
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 | class ExecutionWithPartidaBuilder:
"""
Builder base para configuração de execução com partida.
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._use_partida: bool | None = None
self._monthly_partida: bool | None = None
self._starting_model: ModeloPartida | str | None = None
def use_partida(self, enabled: bool) -> "ExecutionWithPartidaBuilder":
if not isinstance(enabled, bool):
raise ValueError("use_partida deve ser boolean.")
self._use_partida = enabled
return self
def set_monthly_partida(self, enabled: bool) -> "ExecutionWithPartidaBuilder":
if not isinstance(enabled, bool):
raise ValueError("monthly_partida deve ser boolean.")
self._monthly_partida = enabled
return self
def set_starting_model(
self,
model: ModeloPartida | str | None,
) -> "ExecutionWithPartidaBuilder":
self._starting_model = model
return self
def clear_starting_model(self) -> "ExecutionWithPartidaBuilder":
self._starting_model = None
return self
def build(self) -> ExecutionPartidaConfigRequest:
if self._use_partida is None:
raise ValueError("use_partida deve ser configurado antes do build().")
if self._monthly_partida is None:
raise ValueError("monthly_partida deve ser configurado antes do build().")
return ExecutionPartidaConfigRequest(
executaPartida="s" if self._use_partida else "n",
partidaMensal=1 if self._monthly_partida else 0,
modeloPartida=(
self._normalize_model(self._starting_model)
if self._use_partida
else None
),
)
def _normalize_model(self, model: ModeloPartida | str | None) -> ModeloPartida | None:
if model is None:
return None
if isinstance(model, ModeloPartida):
return model
normalized_model = str(model).strip().upper()
aliases = {
"NEWAVE": ModeloPartida.NEWAVE,
"NW": ModeloPartida.NEWAVE,
"DECOMP": ModeloPartida.DECOMP,
"DC": ModeloPartida.DECOMP,
"GEVAZP": ModeloPartida.GEVAZP,
"GV": ModeloPartida.GEVAZP,
}
try:
return aliases[normalized_model]
except KeyError as error:
raise ValueError(
"starting_model deve ser NEWAVE, DECOMP, GEVAZP ou os códigos NW, DC e GV."
) from error
|