# coding: utf-8

"""
    bxb API

    A comprehensive usage-based billing platform API. Manage customers, plans, subscriptions, invoices, payments, wallets, coupons, credit notes, taxes, webhooks, and more.

    The version of the OpenAPI document: 0.5.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from uuid import UUID
from typing import Optional, Set
from typing_extensions import Self

class BillingEntityResponse(BaseModel):
    """
    BillingEntityResponse
    """ # noqa: E501
    id: UUID
    code: StrictStr
    name: StrictStr
    legal_name: Optional[StrictStr]
    address_line1: Optional[StrictStr]
    address_line2: Optional[StrictStr]
    city: Optional[StrictStr]
    state: Optional[StrictStr]
    country: Optional[StrictStr]
    zip_code: Optional[StrictStr]
    tax_id: Optional[StrictStr]
    email: Optional[StrictStr]
    currency: StrictStr
    timezone: StrictStr
    document_locale: StrictStr
    invoice_prefix: Optional[StrictStr]
    next_invoice_number: StrictInt
    invoice_grace_period: StrictInt
    net_payment_term: StrictInt
    invoice_footer: Optional[StrictStr]
    is_default: StrictBool
    created_at: datetime
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["id", "code", "name", "legal_name", "address_line1", "address_line2", "city", "state", "country", "zip_code", "tax_id", "email", "currency", "timezone", "document_locale", "invoice_prefix", "next_invoice_number", "invoice_grace_period", "net_payment_term", "invoice_footer", "is_default", "created_at", "updated_at"]

    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 BillingEntityResponse 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 legal_name (nullable) is None
        # and model_fields_set contains the field
        if self.legal_name is None and "legal_name" in self.model_fields_set:
            _dict['legal_name'] = None

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of BillingEntityResponse 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"),
            "code": obj.get("code"),
            "name": obj.get("name"),
            "legal_name": obj.get("legal_name"),
            "address_line1": obj.get("address_line1"),
            "address_line2": obj.get("address_line2"),
            "city": obj.get("city"),
            "state": obj.get("state"),
            "country": obj.get("country"),
            "zip_code": obj.get("zip_code"),
            "tax_id": obj.get("tax_id"),
            "email": obj.get("email"),
            "currency": obj.get("currency"),
            "timezone": obj.get("timezone"),
            "document_locale": obj.get("document_locale"),
            "invoice_prefix": obj.get("invoice_prefix"),
            "next_invoice_number": obj.get("next_invoice_number"),
            "invoice_grace_period": obj.get("invoice_grace_period"),
            "net_payment_term": obj.get("net_payment_term"),
            "invoice_footer": obj.get("invoice_footer"),
            "is_default": obj.get("is_default"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


