# coding: utf-8

"""
    Pinterest REST API

    Pinterest's REST API

    The version of the OpenAPI document: 5.23.0
    Contact: blah+oapicf@cliffano.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 date
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.currency import Currency
from typing import Optional, Set
from typing_extensions import Self

class BillingInvoiceResponse(BaseModel):
    """
    BillingInvoiceResponse
    """ # noqa: E501
    ad_account_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The ID of the ad account this invoice belongs to")
    ad_account_name: Optional[StrictStr] = Field(default=None, description="The name of the ad account this invoice belongs to")
    amount_billed_micro_currency: Optional[StrictInt] = Field(default=None, description="The amount billed in this invoice. Denoted in micro currency")
    amount_discount_micro_currency: Optional[StrictInt] = Field(default=None, description="The discount in this invoice. Denoted in micro currency")
    amount_net_micro_currency: Optional[StrictInt] = Field(default=None, description="The net amount in this invoice. Denoted in micro currency")
    amount_tax_micro_currency: Optional[StrictInt] = Field(default=None, description="The tax in this invoice. Denoted in micro currency")
    bill_to_country: Optional[StrictStr] = Field(default=None, description="The country of the bill to address")
    billing_period_end_date: Optional[date] = Field(default=None, description="The end date of the billing period. Format: YYYY-MM-DD")
    billing_period_start_date: Optional[date] = Field(default=None, description="The start date of the billing period. Format: YYYY-MM-DD")
    currency: Optional[Currency] = None
    document_type: Optional[StrictStr] = Field(default=None, description="The type of the document")
    id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Unique identifier for the billing invoice")
    invoice_due_date: Optional[date] = Field(default=None, description="The date the invoice is due. Format: YYYY-MM-DD")
    payment_terms: Optional[StrictStr] = Field(default=None, description="The payment terms of the invoice")
    status: Optional[StrictStr] = Field(default=None, description="The status of the invoice")
    __properties: ClassVar[List[str]] = ["ad_account_id", "ad_account_name", "amount_billed_micro_currency", "amount_discount_micro_currency", "amount_net_micro_currency", "amount_tax_micro_currency", "bill_to_country", "billing_period_end_date", "billing_period_start_date", "currency", "document_type", "id", "invoice_due_date", "payment_terms", "status"]

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

        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        return value

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

        if not re.match(r"^(\d{4})-(\d{2})-(\d{2})$", value):
            raise ValueError(r"must validate the regular expression /^(\d{4})-(\d{2})-(\d{2})$/")
        return value

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

        if not re.match(r"^(\d{4})-(\d{2})-(\d{2})$", value):
            raise ValueError(r"must validate the regular expression /^(\d{4})-(\d{2})-(\d{2})$/")
        return value

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

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

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

        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        return value

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

        if not re.match(r"^(\d{4})-(\d{2})-(\d{2})$", value):
            raise ValueError(r"must validate the regular expression /^(\d{4})-(\d{2})-(\d{2})$/")
        return value

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

        if value not in set(['OPEN', 'CLOSED']):
            raise ValueError("must be one of enum values ('OPEN', 'CLOSED')")
        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 BillingInvoiceResponse 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 amount_discount_micro_currency (nullable) is None
        # and model_fields_set contains the field
        if self.amount_discount_micro_currency is None and "amount_discount_micro_currency" in self.model_fields_set:
            _dict['amount_discount_micro_currency'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "ad_account_id": obj.get("ad_account_id"),
            "ad_account_name": obj.get("ad_account_name"),
            "amount_billed_micro_currency": obj.get("amount_billed_micro_currency"),
            "amount_discount_micro_currency": obj.get("amount_discount_micro_currency"),
            "amount_net_micro_currency": obj.get("amount_net_micro_currency"),
            "amount_tax_micro_currency": obj.get("amount_tax_micro_currency"),
            "bill_to_country": obj.get("bill_to_country"),
            "billing_period_end_date": obj.get("billing_period_end_date"),
            "billing_period_start_date": obj.get("billing_period_start_date"),
            "currency": obj.get("currency"),
            "document_type": obj.get("document_type"),
            "id": obj.get("id"),
            "invoice_due_date": obj.get("invoice_due_date"),
            "payment_terms": obj.get("payment_terms"),
            "status": obj.get("status")
        })
        return _obj


