# 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, List, Optional
from pydantic import BaseModel, Field, StrictBool, conlist
from warg_openapi.models.fetch_warning import FetchWarning
from warg_openapi.models.published_record_envelope import PublishedRecordEnvelope

class FetchLogsResponse(BaseModel):
    """
    A response containing the requested logs.  # noqa: E501
    """
    more: Optional[StrictBool] = Field(default=None, description="Whether there may be more records available.  This occurs when the number of records returned for a log reaches the requested limit.  If `true`, the client should make another request with the new last known record identifiers. ")
    operator: Optional[conlist(PublishedRecordEnvelope, max_items=1000)] = Field(default=None, description="The operator log records for the given checkpoint since the last known record.")
    warnings: Optional[conlist(FetchWarning, max_items=1000)] = Field(default=None, description="An optional list of warnings.")
    packages: Optional[Dict[str, Any]] = Field(default=None, description="The map of package log identifier to package records.")
    __properties = ["more", "operator", "warnings", "packages"]

    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) -> FetchLogsResponse:
        """Create an instance of FetchLogsResponse 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 each item in operator (list)
        _items = []
        if self.operator:
            for _item in self.operator:
                if _item:
                    _items.append(_item.to_dict())
            _dict['operator'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in warnings (list)
        _items = []
        if self.warnings:
            for _item in self.warnings:
                if _item:
                    _items.append(_item.to_dict())
            _dict['warnings'] = _items
        return _dict

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

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

        _obj = FetchLogsResponse.parse_obj({
            "more": obj.get("more"),
            "operator": [PublishedRecordEnvelope.from_dict(_item) for _item in obj.get("operator")] if obj.get("operator") is not None else None,
            "warnings": [FetchWarning.from_dict(_item) for _item in obj.get("warnings")] if obj.get("warnings") is not None else None,
            "packages": obj.get("packages")
        })
        return _obj


