from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.yara_rule_model import YaraRuleModel


T = TypeVar("T", bound="MalwareBackupScanSpecEngine")


@_attrs_define
class MalwareBackupScanSpecEngine:
    """Type of backup scan engine.

    Attributes:
        use_antivirus_engine (bool): If `true`, the selected backup is scanned with antivirus software.
        use_yara_rule (bool): If `true`, the selected backup is scanned with the specified YARA rule.
        yara_rule (YaraRuleModel | Unset): YARA rule file name.
    """

    use_antivirus_engine: bool
    use_yara_rule: bool
    yara_rule: YaraRuleModel | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        use_antivirus_engine = self.use_antivirus_engine

        use_yara_rule = self.use_yara_rule

        yara_rule: dict[str, Any] | Unset = UNSET
        if not isinstance(self.yara_rule, Unset):
            yara_rule = self.yara_rule.to_dict()

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "useAntivirusEngine": use_antivirus_engine,
                "useYaraRule": use_yara_rule,
            }
        )
        if yara_rule is not UNSET:
            field_dict["yaraRule"] = yara_rule

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.yara_rule_model import YaraRuleModel

        d = dict(src_dict)
        use_antivirus_engine = d.pop("useAntivirusEngine")

        use_yara_rule = d.pop("useYaraRule")

        _yara_rule = d.pop("yaraRule", UNSET)
        yara_rule: YaraRuleModel | Unset
        if isinstance(_yara_rule, Unset):
            yara_rule = UNSET
        else:
            yara_rule = YaraRuleModel.from_dict(_yara_rule)

        malware_backup_scan_spec_engine = cls(
            use_antivirus_engine=use_antivirus_engine,
            use_yara_rule=use_yara_rule,
            yara_rule=yara_rule,
        )

        malware_backup_scan_spec_engine.additional_properties = d
        return malware_backup_scan_spec_engine

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
