# coding: utf-8

"""
    Arthur Scope

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.1.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from arthur_client.api_bindings.models.post_policy_alert_rule import PostPolicyAlertRule
from arthur_client.api_bindings.models.post_policy_attestation_rule import PostPolicyAttestationRule
from typing import Optional, Set
from typing_extensions import Self

class PostPolicy(BaseModel):
    """
    PostPolicy
    """ # noqa: E501
    name: StrictStr = Field(description="The name of the policy.")
    description: Optional[StrictStr] = None
    owner_group_id: StrictStr = Field(description="The ID of the group that owns this policy.")
    webhook_id: StrictStr = Field(description="The ID of the notification webhook.")
    enforcement_delay_days: StrictInt = Field(description="The number of days for the enforcement delay.")
    alert_rules: Optional[List[PostPolicyAlertRule]] = Field(default=None, description="Alert rules to create with the policy.")
    attestation_rules: Optional[List[PostPolicyAttestationRule]] = Field(default=None, description="Attestation rules to create with the policy.")
    __properties: ClassVar[List[str]] = ["name", "description", "owner_group_id", "webhook_id", "enforcement_delay_days", "alert_rules", "attestation_rules"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of PostPolicy from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in alert_rules (list)
        _items = []
        if self.alert_rules:
            for _item_alert_rules in self.alert_rules:
                if _item_alert_rules:
                    _items.append(_item_alert_rules.to_dict())
            _dict['alert_rules'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in attestation_rules (list)
        _items = []
        if self.attestation_rules:
            for _item_attestation_rules in self.attestation_rules:
                if _item_attestation_rules:
                    _items.append(_item_attestation_rules.to_dict())
            _dict['attestation_rules'] = _items
        # set to None if description (nullable) is None
        # and model_fields_set contains the field
        if self.description is None and "description" in self.model_fields_set:
            _dict['description'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of PostPolicy from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "description": obj.get("description"),
            "owner_group_id": obj.get("owner_group_id"),
            "webhook_id": obj.get("webhook_id"),
            "enforcement_delay_days": obj.get("enforcement_delay_days"),
            "alert_rules": [PostPolicyAlertRule.from_dict(_item) for _item in obj["alert_rules"]] if obj.get("alert_rules") is not None else None,
            "attestation_rules": [PostPolicyAttestationRule.from_dict(_item) for _item in obj["attestation_rules"]] if obj.get("attestation_rules") is not None else None
        })
        return _obj


