# coding: utf-8

"""
    Warg Registry API

    [warg](https://warg.io/) is an open source protocol for WebAssembly component registries. 

    The version of the OpenAPI document: 1.0.0
    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 typing import Any, Dict, Optional
from pydantic import BaseModel, Field, constr
from warg_openapi.models.envelope_body import EnvelopeBody

class PublishPackageRecordRequest(BaseModel):
    """
    A request to publish a record to a package log.  # noqa: E501
    """
    package_name: constr(strict=True, max_length=128) = Field(default=..., alias="packageName", description="The name of the package log being published to.")
    record: EnvelopeBody = Field(default=..., description="The package record being published to the log.")
    content_sources: Optional[Dict[str, Any]] = Field(default=None, alias="contentSources", description="The map of content digest to sources.")
    __properties = ["packageName", "record", "contentSources"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> PublishPackageRecordRequest:
        """Create an instance of PublishPackageRecordRequest from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of record
        if self.record:
            _dict['record'] = self.record.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> PublishPackageRecordRequest:
        """Create an instance of PublishPackageRecordRequest from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return PublishPackageRecordRequest.parse_obj(obj)

        _obj = PublishPackageRecordRequest.parse_obj({
            "package_name": obj.get("packageName"),
            "record": EnvelopeBody.from_dict(obj.get("record")) if obj.get("record") is not None else None,
            "content_sources": obj.get("contentSources")
        })
        return _obj


