# coding: utf-8

"""
    Vayu API

    The Vayu API is a RESTful API that allows you to submit events for processing and storage & manage billing related entities.           The API is secured using the Bearer Authentication scheme with JWT tokens.           To obtain a JWT token, please contact Vayu at team@withvayu.com

    The version of the OpenAPI document: 1.0.0
    Contact: dev@withvayu.com
    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, StrictFloat, StrictInt, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from openapi_client.models.get_invoice_response_schema_invoice_line_items_inner import GetInvoiceResponseSchemaInvoiceLineItemsInner
from openapi_client.models.period import Period
from typing import Optional, Set
from typing_extensions import Self

class ListInvoicesResponseSchemaInvoicesInner(BaseModel):
    """
    ListInvoicesResponseSchemaInvoicesInner
    """ # noqa: E501
    customer_id: Annotated[str, Field(strict=True)] = Field(description="The id of the customer that the invoice is associated with", alias="customerId")
    contract_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The id of the contract that the invoice is associated with", alias="contractId")
    amount: Union[StrictFloat, StrictInt] = Field(description="The amount to be charged in the invoice")
    name: Annotated[str, Field(min_length=1, strict=True)] = Field(description="The name of the invoice, usually a description of the billing period")
    billing_cycle: Period = Field(alias="billingCycle")
    line_items: List[GetInvoiceResponseSchemaInvoiceLineItemsInner] = Field(alias="lineItems")
    id: Annotated[str, Field(strict=True)]
    created_at: datetime = Field(alias="createdAt")
    updated_at: datetime = Field(alias="updatedAt")
    __properties: ClassVar[List[str]] = ["customerId", "contractId", "amount", "name", "billingCycle", "lineItems", "id", "createdAt", "updatedAt"]

    @field_validator('customer_id')
    def customer_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[0-9a-fA-F]{24}$", value):
            raise ValueError(r"must validate the regular expression /^[0-9a-fA-F]{24}$/")
        return value

    @field_validator('contract_id')
    def contract_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[0-9a-fA-F]{24}$", value):
            raise ValueError(r"must validate the regular expression /^[0-9a-fA-F]{24}$/")
        return value

    @field_validator('id')
    def id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[0-9a-fA-F]{24}$", value):
            raise ValueError(r"must validate the regular expression /^[0-9a-fA-F]{24}$/")
        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 ListInvoicesResponseSchemaInvoicesInner 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 billing_cycle
        if self.billing_cycle:
            _dict['billingCycle'] = self.billing_cycle.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in line_items (list)
        _items = []
        if self.line_items:
            for _item in self.line_items:
                if _item:
                    _items.append(_item.to_dict())
            _dict['lineItems'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "customerId": obj.get("customerId"),
            "contractId": obj.get("contractId"),
            "amount": obj.get("amount"),
            "name": obj.get("name"),
            "billingCycle": Period.from_dict(obj["billingCycle"]) if obj.get("billingCycle") is not None else None,
            "lineItems": [GetInvoiceResponseSchemaInvoiceLineItemsInner.from_dict(_item) for _item in obj["lineItems"]] if obj.get("lineItems") is not None else None,
            "id": obj.get("id"),
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt")
        })
        return _obj


