"""CIS Controls Official Structure Models.

These models were generated by xsdata from actual CIS XCCDF files and represent
the official CIS Controls structure used in CIS-CAT benchmarks.

Source: CIS_Google_Chrome_Benchmark_v2.1.0-xccdf.xml (reversed with xsdata)
Namespace: http://cisecurity.org/controls
"""

from dataclasses import dataclass, field


@dataclass
class ImplementationGroups:
    """Implementation Group flags for CIS Controls.

    Indicates which implementation groups (IG1, IG2, IG3) this control applies to.
    """

    class Meta:
        name = "implementation_groups"
        namespace = "http://cisecurity.org/controls"

    ig1: bool | None = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )
    ig2: bool | None = field(
        default=None,
        metadata={
            "type": "Attribute",
        },
    )
    ig3: bool | None = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )


@dataclass
class Safeguard:
    """Individual CIS Control safeguard.

    Represents a specific security control within a CIS Controls framework version.

    Example:
        <safeguard title="Use Unique Passwords"
                   urn="urn:cisecurity.org:controls:8.0:5:2">
          <implementation_groups ig1="true" ig2="true" ig3="true"/>
          <asset_type>Users</asset_type>
          <security_function>Protect</security_function>
        </safeguard>
    """

    class Meta:
        name = "safeguard"
        namespace = "http://cisecurity.org/controls"

    title: str | None = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    urn: str | None = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    implementation_groups: ImplementationGroups | None = field(
        default=None,
        metadata={
            "type": "Element",
            "required": True,
        },
    )
    asset_type: str | None = field(
        default=None,
        metadata={
            "type": "Element",
            "required": True,
        },
    )
    security_function: str | None = field(
        default=None,
        metadata={
            "type": "Element",
            "required": True,
        },
    )


@dataclass
class Framework:
    """CIS Controls framework version container.

    Groups safeguards for a specific version (7.0, 8.0, etc.) of the CIS Controls.

    Example:
        <framework urn="urn:cisecurity.org:controls:8.0">
          <safeguard>...</safeguard>
          <safeguard>...</safeguard>
        </framework>
    """

    class Meta:
        name = "framework"
        namespace = "http://cisecurity.org/controls"

    urn: str | None = field(
        default=None,
        metadata={
            "type": "Attribute",
            "required": True,
        },
    )
    safeguard: list[Safeguard] = field(
        default_factory=list,
        metadata={
            "type": "Element",
            "min_occurs": 1,
        },
    )


@dataclass
class CisControls:
    """Top-level CIS Controls metadata structure.

    Contains one or more framework elements (typically v7.0 and v8.0).
    Used within XCCDF <metadata> element.

    Example:
        <cis_controls xmlns="http://cisecurity.org/controls">
          <framework urn="urn:cisecurity.org:controls:8.0">
            <safeguard>...</safeguard>
          </framework>
          <framework urn="urn:cisecurity.org:controls:7.0">
            <safeguard>...</safeguard>
          </framework>
        </cis_controls>
    """

    class Meta:
        name = "cis_controls"
        namespace = "http://cisecurity.org/controls"

    framework: list[Framework] = field(
        default_factory=list,
        metadata={
            "type": "Element",
            "min_occurs": 1,
        },
    )
