# coding: utf-8

"""
    Artifact Keeper API

    Enterprise artifact registry supporting 45+ package formats.

    The version of the OpenAPI document: 1.0.0-rc.3
    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class CreateRepositoryRequest(BaseModel):
    """
    CreateRepositoryRequest
    """ # noqa: E501
    description: Optional[StrictStr] = None
    format: StrictStr
    format_key: Optional[StrictStr] = Field(default=None, description="Custom format key for WASM plugin format handlers (e.g. \"rpm-custom\").")
    index_upstream_url: Optional[StrictStr] = Field(default=None, description="Separate index host for Cargo registries that split index and download across two hosts (e.g. crates.io uses `https://index.crates.io` for the sparse index but `https://crates.io` for tarball downloads). Stored in `repository_config` under the key `index_upstream_url`.")
    is_public: Optional[StrictBool] = None
    key: StrictStr
    name: StrictStr
    quota_bytes: Optional[StrictInt] = None
    repo_type: StrictStr
    upstream_url: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["description", "format", "format_key", "index_upstream_url", "is_public", "key", "name", "quota_bytes", "repo_type", "upstream_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 CreateRepositoryRequest 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,
        )
        # set to None if description (nullable) is None
        # and model_fields_set contains the field
        if self.description is None and "description" in self.model_fields_set:
            _dict['description'] = None

        # set to None if format_key (nullable) is None
        # and model_fields_set contains the field
        if self.format_key is None and "format_key" in self.model_fields_set:
            _dict['format_key'] = None

        # set to None if index_upstream_url (nullable) is None
        # and model_fields_set contains the field
        if self.index_upstream_url is None and "index_upstream_url" in self.model_fields_set:
            _dict['index_upstream_url'] = None

        # set to None if is_public (nullable) is None
        # and model_fields_set contains the field
        if self.is_public is None and "is_public" in self.model_fields_set:
            _dict['is_public'] = None

        # set to None if quota_bytes (nullable) is None
        # and model_fields_set contains the field
        if self.quota_bytes is None and "quota_bytes" in self.model_fields_set:
            _dict['quota_bytes'] = None

        # set to None if upstream_url (nullable) is None
        # and model_fields_set contains the field
        if self.upstream_url is None and "upstream_url" in self.model_fields_set:
            _dict['upstream_url'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "description": obj.get("description"),
            "format": obj.get("format"),
            "format_key": obj.get("format_key"),
            "index_upstream_url": obj.get("index_upstream_url"),
            "is_public": obj.get("is_public"),
            "key": obj.get("key"),
            "name": obj.get("name"),
            "quota_bytes": obj.get("quota_bytes"),
            "repo_type": obj.get("repo_type"),
            "upstream_url": obj.get("upstream_url")
        })
        return _obj


