# coding: utf-8

"""
    STACKIT Observability API

    API endpoints for Observability on STACKIT

    The version of the OpenAPI document: 1.1.1
    Contact: stackit-argus@mail.schwarz
    Generated by OpenAPI Generator (https://openapi-generator.tech)

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

from __future__ import annotations

import json
import pprint
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field
from typing_extensions import Annotated, Self

from stackit.observability.models.partial_update_scrape_configs_request_inner_basic_auth import (
    PartialUpdateScrapeConfigsRequestInnerBasicAuth,
)
from stackit.observability.models.partial_update_scrape_configs_request_inner_http_sd_configs_inner_oauth2 import (
    PartialUpdateScrapeConfigsRequestInnerHttpSdConfigsInnerOauth2,
)
from stackit.observability.models.partial_update_scrape_configs_request_inner_http_sd_configs_inner_oauth2_tls_config import (
    PartialUpdateScrapeConfigsRequestInnerHttpSdConfigsInnerOauth2TlsConfig,
)


class PartialUpdateScrapeConfigsRequestInnerHttpSdConfigsInner(BaseModel):
    """
    PartialUpdateScrapeConfigsRequestInnerHttpSdConfigsInner
    """  # noqa: E501

    basic_auth: Optional[PartialUpdateScrapeConfigsRequestInnerBasicAuth] = Field(default=None, alias="basicAuth")
    oauth2: Optional[PartialUpdateScrapeConfigsRequestInnerHttpSdConfigsInnerOauth2] = None
    refresh_interval: Optional[Annotated[str, Field(min_length=2, strict=True, max_length=8)]] = Field(
        default="60s",
        description="Refresh interval to re-query the endpoint. E.g. 60s `Additional Validators:` * must be a valid time format* must be >= 60s",
        alias="refreshInterval",
    )
    tls_config: Optional[PartialUpdateScrapeConfigsRequestInnerHttpSdConfigsInnerOauth2TlsConfig] = Field(
        default=None, alias="tlsConfig"
    )
    url: Annotated[str, Field(strict=True, max_length=400)] = Field(
        description="URL from which the targets are fetched."
    )
    __properties: ClassVar[List[str]] = ["basicAuth", "oauth2", "refreshInterval", "tlsConfig", "url"]

    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 PartialUpdateScrapeConfigsRequestInnerHttpSdConfigsInner 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 basic_auth
        if self.basic_auth:
            _dict["basicAuth"] = self.basic_auth.to_dict()
        # override the default output from pydantic by calling `to_dict()` of oauth2
        if self.oauth2:
            _dict["oauth2"] = self.oauth2.to_dict()
        # override the default output from pydantic by calling `to_dict()` of tls_config
        if self.tls_config:
            _dict["tlsConfig"] = self.tls_config.to_dict()
        return _dict

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

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

        _obj = cls.model_validate(
            {
                "basicAuth": (
                    PartialUpdateScrapeConfigsRequestInnerBasicAuth.from_dict(obj["basicAuth"])
                    if obj.get("basicAuth") is not None
                    else None
                ),
                "oauth2": (
                    PartialUpdateScrapeConfigsRequestInnerHttpSdConfigsInnerOauth2.from_dict(obj["oauth2"])
                    if obj.get("oauth2") is not None
                    else None
                ),
                "refreshInterval": obj.get("refreshInterval") if obj.get("refreshInterval") is not None else "60s",
                "tlsConfig": (
                    PartialUpdateScrapeConfigsRequestInnerHttpSdConfigsInnerOauth2TlsConfig.from_dict(obj["tlsConfig"])
                    if obj.get("tlsConfig") is not None
                    else None
                ),
                "url": obj.get("url"),
            }
        )
        return _obj
