"""The module that defines the ``AttestDefenseDimensionWeights`` model.
SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""
from __future__ import annotations
import typing as t
from dataclasses import dataclass, field
import cg_request_args as rqa
from ..utils import to_dict
[docs]
@dataclass(kw_only=True)
class AttestDefenseDimensionWeights:
"""How often the defense asks about each dimension."""
#: The weight of the direction dimension.
direction: t.Literal["never", "often", "sometimes"]
#: The weight of the verification dimension.
verification: t.Literal["never", "often", "sometimes"]
#: The weight of the correction dimension.
correction: t.Literal["never", "often", "sometimes"]
#: The weight of the ownership dimension.
ownership: t.Literal["never", "often", "sometimes"]
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar[t.Any] = rqa.Lazy(
lambda: rqa.FixedMapping(
rqa.RequiredArgument(
"direction",
rqa.StringEnum("never", "often", "sometimes"),
doc="The weight of the direction dimension.",
),
rqa.RequiredArgument(
"verification",
rqa.StringEnum("never", "often", "sometimes"),
doc="The weight of the verification dimension.",
),
rqa.RequiredArgument(
"correction",
rqa.StringEnum("never", "often", "sometimes"),
doc="The weight of the correction dimension.",
),
rqa.RequiredArgument(
"ownership",
rqa.StringEnum("never", "often", "sometimes"),
doc="The weight of the ownership dimension.",
),
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"direction": to_dict(self.direction),
"verification": to_dict(self.verification),
"correction": to_dict(self.correction),
"ownership": to_dict(self.ownership),
}
return res
@classmethod
def from_dict(
cls: t.Type[AttestDefenseDimensionWeights], d: t.Dict[str, t.Any]
) -> AttestDefenseDimensionWeights:
parsed = cls.data_parser.try_parse(d)
res = cls(
direction=parsed.direction,
verification=parsed.verification,
correction=parsed.correction,
ownership=parsed.ownership,
)
res.raw_data = d
return res