# coding: utf-8

"""
    PAY.JP API v2

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 2.0.0
    Contact: support@pay.jp
    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, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from payjpv2.models.statement_item_response import StatementItemResponse
from payjpv2.models.statement_type import StatementType
from payjpv2.models.term_response import TermResponse
from typing import Optional, Set
from typing_extensions import Self

class StatementResponse(BaseModel):
    """
    StatementResponse
    """ # noqa: E501
    object: Optional[StrictStr] = 'statement'
    id: StrictStr = Field(description="明細ID")
    livemode: StrictBool = Field(description="本番環境かどうか")
    title: Optional[StrictStr]
    type: StatementType = Field(description="取引明細の区分  | 名 | 区分 | 詳細 | |---| --- | --- | | **sales** | 売上 | 決済による売上、決済手数料等 | | **service_fee** | サービス利用料 | 有料プランの月額費用など、salesに含まれないサービス利用料 | | **forfeit** | 残高失効 | - | | **transfer_fee** | 振込手数料 | - | | **misc** | その他 | 調整金など |")
    created_at: datetime = Field(description="更新時の日時 (UTC, ISO 8601 形式)")
    updated_at: datetime = Field(description="更新時の日時 (UTC, ISO 8601 形式)")
    term: Optional[TermResponse]
    balance_id: Optional[StrictStr]
    items: List[StatementItemResponse] = Field(description="明細項目のリスト")
    net: StrictInt = Field(description="含まれるstatement_itemの金額合計")
    __properties: ClassVar[List[str]] = ["object", "id", "livemode", "title", "type", "created_at", "updated_at", "term", "balance_id", "items", "net"]

    @field_validator('object')
    def object_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['statement']):
            raise ValueError("must be one of enum values ('statement')")
        return value

    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"""
        return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of StatementResponse 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 term
        if self.term:
            _dict['term'] = self.term.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in items (list)
        _items = []
        if self.items:
            for _item_items in self.items:
                if _item_items:
                    _items.append(_item_items.to_dict())
            _dict['items'] = _items
        # set to None if title (nullable) is None
        # and model_fields_set contains the field
        if self.title is None and "title" in self.model_fields_set:
            _dict['title'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "object": obj.get("object") if obj.get("object") is not None else 'statement',
            "id": obj.get("id"),
            "livemode": obj.get("livemode"),
            "title": obj.get("title"),
            "type": obj.get("type"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "term": TermResponse.from_dict(obj["term"]) if obj.get("term") is not None else None,
            "balance_id": obj.get("balance_id"),
            "items": [StatementItemResponse.from_dict(_item) for _item in obj["items"]] if obj.get("items") is not None else None,
            "net": obj.get("net")
        })
        return _obj


