# coding: utf-8

"""
    Ringer Business API

    This API provides comprehensive endpoints for the Ringer Business system. It includes functionality for managing customer accounts, addresses, sites,  phone numbers, payments, users, and other business resources.  Operations typically require authentication and appropriate permissions. 

    The version of the OpenAPI document: 1.0.4
    Contact: support@ringer.tel
    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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from ringer_business.models.schemas_link import SchemasLink
from typing import Optional, Set
from typing_extensions import Self

class StatementResponse(BaseModel):
    """
    Detailed information about a specific account statement.
    """ # noqa: E501
    id: StrictInt = Field(description="Unique identifier for the statement.")
    statement_number: Optional[StrictStr] = Field(default=None, description="A human-readable identifier for the statement (e.g., STMT-2023-10-001).")
    period_start: datetime = Field(description="The start date and time of the service period covered by this statement.")
    period_end: datetime = Field(description="The end date and time of the service period covered by this statement.")
    issue_date: datetime = Field(description="The date when the statement was issued.")
    due_date: Optional[datetime] = Field(default=None, description="The date when payment for this statement is due.")
    total_amount: StrictStr = Field(description="The total amount due or charged on this statement.")
    currency: StrictStr = Field(description="Three-letter ISO currency code for the amounts on the statement.")
    status: StrictStr = Field(description="The current status of the statement.")
    created_at_original: Optional[StrictStr] = Field(default=None, description="Original creation date string from legacy system, if applicable.")
    closed_at_original: Optional[StrictStr] = Field(default=None, description="Original closing date string from legacy system, if applicable.")
    image_url: Optional[StrictStr] = Field(default=None, description="URL to an image representation of the statement (e.g., a PNG or JPG).")
    pdf_url: Optional[StrictStr] = Field(default=None, description="URL to download the statement in PDF format.")
    cdr_export_url: Optional[StrictStr] = Field(default=None, description="URL to download associated Call Detail Records (CDRs) for this statement period, typically in CSV format.")
    links: Optional[List[SchemasLink]] = Field(default=None, description="HATEOAS links related to this statement.")
    __properties: ClassVar[List[str]] = ["id", "statement_number", "period_start", "period_end", "issue_date", "due_date", "total_amount", "currency", "status", "created_at_original", "closed_at_original", "image_url", "pdf_url", "cdr_export_url", "links"]

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['open', 'paid', 'overdue', 'void', 'uncollectible']):
            raise ValueError("must be one of enum values ('open', 'paid', 'overdue', 'void', 'uncollectible')")
        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"""
        # 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 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 each item in links (list)
        _items = []
        if self.links:
            for _item_links in self.links:
                if _item_links:
                    _items.append(_item_links.to_dict())
            _dict['links'] = _items
        # set to None if statement_number (nullable) is None
        # and model_fields_set contains the field
        if self.statement_number is None and "statement_number" in self.model_fields_set:
            _dict['statement_number'] = None

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

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

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

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

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

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

        # set to None if links (nullable) is None
        # and model_fields_set contains the field
        if self.links is None and "links" in self.model_fields_set:
            _dict['links'] = 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({
            "id": obj.get("id"),
            "statement_number": obj.get("statement_number"),
            "period_start": obj.get("period_start"),
            "period_end": obj.get("period_end"),
            "issue_date": obj.get("issue_date"),
            "due_date": obj.get("due_date"),
            "total_amount": obj.get("total_amount"),
            "currency": obj.get("currency") if obj.get("currency") is not None else 'USD',
            "status": obj.get("status"),
            "created_at_original": obj.get("created_at_original"),
            "closed_at_original": obj.get("closed_at_original"),
            "image_url": obj.get("image_url"),
            "pdf_url": obj.get("pdf_url"),
            "cdr_export_url": obj.get("cdr_export_url"),
            "links": [SchemasLink.from_dict(_item) for _item in obj["links"]] if obj.get("links") is not None else None
        })
        return _obj


