# coding: utf-8

"""
    Instana REST API documentation

    Documentation for INSTANA REST API

    The version of the OpenAPI document: 1.309.1268
    Contact: support@instana.com
    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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.maintenance_config_scheduling import MaintenanceConfigScheduling
from instana_client.models.occurrence import Occurrence
from instana_client.models.tag_filter_expression_element import TagFilterExpressionElement
from typing import Optional, Set
from typing_extensions import Self

class MaintenanceConfigV2WithStateAndOccurrence(BaseModel):
    """
    MaintenanceConfigV2WithStateAndOccurrence
    """ # noqa: E501
    id: Annotated[str, Field(min_length=0, strict=True, max_length=64)] = Field(description="ID of the Maintenance Window configuration.")
    last_updated: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=None, alias="lastUpdated")
    name: Annotated[str, Field(min_length=0, strict=True, max_length=256)] = Field(description="Name of the Maintenance Window configuration.")
    occurrence: Occurrence
    paused: Optional[StrictBool] = Field(default=None, description="Boolean flag to determine if the Maintenance Window configuration is paused or still live.")
    query: Annotated[str, Field(min_length=0, strict=True, max_length=2048)] = Field(description="Dynamic Focus Query that determines the scope of the Maintenance Window configuration.")
    retrigger_open_alerts_enabled: Optional[StrictBool] = Field(default=None, description="Boolean flag to determine if we should retrigger open alerts to be sent out for any events that opened during this maintenance window, and continues to remain open after the window expires", alias="retriggerOpenAlertsEnabled")
    scheduling: MaintenanceConfigScheduling
    state: Optional[StrictStr] = Field(default=None, description="State of the Maintenance Window, it can be: UNSCHEDULED, SCHEDULED, ACTIVE, PAUSED, EXPIRED.")
    tag_filter_expression: Optional[TagFilterExpressionElement] = Field(default=None, alias="tagFilterExpression")
    tag_filter_expression_enabled: Optional[StrictBool] = Field(default=None, description="Boolean flag to determine if the tagFilterExpression is enabled.", alias="tagFilterExpressionEnabled")
    __properties: ClassVar[List[str]] = ["id", "lastUpdated", "name", "occurrence", "paused", "query", "retriggerOpenAlertsEnabled", "scheduling", "state", "tagFilterExpression", "tagFilterExpressionEnabled"]

    @field_validator('state')
    def state_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['UNSCHEDULED', 'SCHEDULED', 'ACTIVE', 'PAUSED', 'EXPIRED']):
            raise ValueError("must be one of enum values ('UNSCHEDULED', 'SCHEDULED', 'ACTIVE', 'PAUSED', 'EXPIRED')")
        return value

    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 MaintenanceConfigV2WithStateAndOccurrence 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 occurrence
        if self.occurrence:
            _dict['occurrence'] = self.occurrence.to_dict()
        # override the default output from pydantic by calling `to_dict()` of scheduling
        if self.scheduling:
            _dict['scheduling'] = self.scheduling.to_dict()
        # override the default output from pydantic by calling `to_dict()` of tag_filter_expression
        if self.tag_filter_expression:
            _dict['tagFilterExpression'] = self.tag_filter_expression.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "lastUpdated": obj.get("lastUpdated"),
            "name": obj.get("name"),
            "occurrence": Occurrence.from_dict(obj["occurrence"]) if obj.get("occurrence") is not None else None,
            "paused": obj.get("paused"),
            "query": obj.get("query"),
            "retriggerOpenAlertsEnabled": obj.get("retriggerOpenAlertsEnabled"),
            "scheduling": MaintenanceConfigScheduling.from_dict(obj["scheduling"]) if obj.get("scheduling") is not None else None,
            "state": obj.get("state"),
            "tagFilterExpression": TagFilterExpressionElement.from_dict(obj["tagFilterExpression"]) if obj.get("tagFilterExpression") is not None else None,
            "tagFilterExpressionEnabled": obj.get("tagFilterExpressionEnabled")
        })
        return _obj


