# coding: utf-8

"""
    Instana REST API documentation

    Documentation for INSTANA REST API

    The version of the OpenAPI document: 1.304.1059
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from instana_client.models.service_level_indicator import ServiceLevelIndicator
from instana_client.models.slo_entity import SloEntity
from instana_client.models.time_window import TimeWindow
from typing import Optional, Set
from typing_extensions import Self

class ServiceLevelObjectiveConfiguration(BaseModel):
    """
    ServiceLevelObjectiveConfiguration
    """ # noqa: E501
    created_date: Optional[datetime] = Field(default=None, description="Created date of Service Levels Objective Configuration", alias="createdDate")
    entity: SloEntity
    id: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=64)]] = Field(default=None, description="Service Levels Objective Configuration ID")
    indicator: ServiceLevelIndicator
    last_updated: Optional[datetime] = Field(default=None, description="Last updated date of Service Levels Objective Configuration", alias="lastUpdated")
    name: StrictStr = Field(description="Name of the Service Levels Objective Configuration")
    tags: List[StrictStr] = Field(description="List of tags associated with Service Levels Objective Configuration")
    target: Union[Annotated[float, Field(le=0.9999, strict=True, gt=0.0)], Annotated[int, Field(le=0, strict=True, gt=0)]] = Field(description="Service Levels Objective Configuration Target")
    time_window: TimeWindow = Field(alias="timeWindow")
    __properties: ClassVar[List[str]] = ["createdDate", "entity", "id", "indicator", "lastUpdated", "name", "tags", "target", "timeWindow"]

    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 ServiceLevelObjectiveConfiguration 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 entity
        if self.entity:
            _dict['entity'] = self.entity.to_dict()
        # override the default output from pydantic by calling `to_dict()` of indicator
        if self.indicator:
            _dict['indicator'] = self.indicator.to_dict()
        # override the default output from pydantic by calling `to_dict()` of time_window
        if self.time_window:
            _dict['timeWindow'] = self.time_window.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "createdDate": obj.get("createdDate"),
            "entity": SloEntity.from_dict(obj["entity"]) if obj.get("entity") is not None else None,
            "id": obj.get("id"),
            "indicator": ServiceLevelIndicator.from_dict(obj["indicator"]) if obj.get("indicator") is not None else None,
            "lastUpdated": obj.get("lastUpdated"),
            "name": obj.get("name"),
            "tags": obj.get("tags"),
            "target": obj.get("target"),
            "timeWindow": TimeWindow.from_dict(obj["timeWindow"]) if obj.get("timeWindow") is not None else None
        })
        return _obj


