# 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
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.application_scope_with_metadata import ApplicationScopeWithMetadata
from instana_client.models.release_scope import ReleaseScope
from instana_client.models.service_scope_with_metadata import ServiceScopeWithMetadata
from typing import Optional, Set
from typing_extensions import Self

class ReleaseWithMetadata(BaseModel):
    """
    ReleaseWithMetadata
    """ # noqa: E501
    applications: Optional[Annotated[List[ApplicationScopeWithMetadata], Field(min_length=0, max_length=10)]] = Field(default=None, description="The list of application perspectives where the release can be viewed.")
    id: Annotated[str, Field(min_length=0, strict=True, max_length=64)] = Field(description="A unique id for a release. For example: `l1wgr3DsQkGLf8u18JiGsg`.")
    last_updated: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=None, description="The timestamp for when the same release is updated. The time measured is in milliseconds. For example: `1742369990000` is `Wednesday, 19 March 2025 07:39:50 GMT`.", alias="lastUpdated")
    name: Annotated[str, Field(min_length=0, strict=True, max_length=256)] = Field(description="The name of the release. For example: `frontend/release-2000`.")
    scopes: Optional[List[ReleaseScope]] = None
    services: Optional[Annotated[List[ServiceScopeWithMetadata], Field(min_length=0, max_length=10)]] = Field(default=None, description="The list of services where the release can be viewed.")
    start: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=None, description="The timestamp for when the release is created. The time measured is in milliseconds. For example: `1742349976000` is `Wednesday, 19 March 2025 02:06:16 GMT`.")
    __properties: ClassVar[List[str]] = ["applications", "id", "lastUpdated", "name", "scopes", "services", "start"]

    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 ReleaseWithMetadata 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 applications (list)
        _items = []
        if self.applications:
            for _item_applications in self.applications:
                if _item_applications:
                    _items.append(_item_applications.to_dict())
            _dict['applications'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in scopes (list)
        _items = []
        if self.scopes:
            for _item_scopes in self.scopes:
                if _item_scopes:
                    _items.append(_item_scopes.to_dict())
            _dict['scopes'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in services (list)
        _items = []
        if self.services:
            for _item_services in self.services:
                if _item_services:
                    _items.append(_item_services.to_dict())
            _dict['services'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "applications": [ApplicationScopeWithMetadata.from_dict(_item) for _item in obj["applications"]] if obj.get("applications") is not None else None,
            "id": obj.get("id"),
            "lastUpdated": obj.get("lastUpdated"),
            "name": obj.get("name"),
            "scopes": [ReleaseScope.from_dict(_item) for _item in obj["scopes"]] if obj.get("scopes") is not None else None,
            "services": [ServiceScopeWithMetadata.from_dict(_item) for _item in obj["services"]] if obj.get("services") is not None else None,
            "start": obj.get("start")
        })
        return _obj


