# coding: utf-8

"""
    Mender API

    Combined API specification for the features of the different Mender backend services, suitable for code generation applications 

    The version of the OpenAPI document: 1
    Contact: support@mender.io
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from mender_client.models.artifact_v1 import ArtifactV1
from typing import Optional, Set
from typing_extensions import Self

class ReleaseV1(BaseModel):
    """
    Groups artifacts with the same release name into a single resource.
    """ # noqa: E501
    name: Optional[StrictStr] = Field(default=None, description="release name. ", alias="Name")
    modified: Optional[datetime] = Field(default=None, description="Last modification time for the release. ")
    artifacts: Optional[List[ArtifactV1]] = Field(default=None, description="List of artifacts for this release.", alias="Artifacts")
    artifacts_count: Optional[StrictInt] = Field(default=None, description="Number of artifacts.", alias="ArtifactsCount")
    tags: Optional[List[StrictStr]] = Field(default=None, description="Tags assigned to the release used for filtering releases. Each tag must be valid a ASCII string and contain only lowercase and uppercase letters, digits, underscores, periods and hyphens.")
    notes: Optional[StrictStr] = Field(default=None, description="Additional information describing a Release limited to 1024 characters. Please use the v2 API to set this field. ")
    __properties: ClassVar[List[str]] = ["Name", "modified", "Artifacts", "ArtifactsCount", "tags", "notes"]

    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 ReleaseV1 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 artifacts (list)
        _items = []
        if self.artifacts:
            for _item_artifacts in self.artifacts:
                if _item_artifacts:
                    _items.append(_item_artifacts.to_dict())
            _dict['Artifacts'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ReleaseV1 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"),
            "modified": obj.get("modified"),
            "Artifacts": [ArtifactV1.from_dict(_item) for _item in obj["Artifacts"]] if obj.get("Artifacts") is not None else None,
            "ArtifactsCount": obj.get("ArtifactsCount"),
            "tags": obj.get("tags"),
            "notes": obj.get("notes")
        })
        return _obj


