# 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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class BillingEntityCreate(BaseModel):
    """
    BillingEntityCreate
    """ # noqa: E501
    code: Annotated[str, Field(min_length=1, strict=True, max_length=100)]
    name: Annotated[str, Field(min_length=1, strict=True, max_length=255)]
    legal_name: Optional[Annotated[str, Field(strict=True, max_length=255)]] = None
    address_line1: Optional[StrictStr] = None
    address_line2: Optional[StrictStr] = None
    city: Optional[StrictStr] = None
    state: Optional[StrictStr] = None
    country: Optional[Annotated[str, Field(min_length=2, strict=True, max_length=2)]] = None
    zip_code: Optional[StrictStr] = None
    tax_id: Optional[StrictStr] = None
    email: Optional[StrictStr] = None
    currency: Optional[Annotated[str, Field(min_length=3, strict=True, max_length=3)]] = 'USD'
    timezone: Optional[Annotated[str, Field(strict=True, max_length=50)]] = 'UTC'
    document_locale: Optional[Annotated[str, Field(strict=True, max_length=10)]] = 'en'
    invoice_prefix: Optional[Annotated[str, Field(strict=True, max_length=20)]] = None
    next_invoice_number: Optional[Annotated[int, Field(strict=True, ge=1)]] = 1
    invoice_grace_period: Optional[Annotated[int, Field(strict=True, ge=0)]] = 0
    net_payment_term: Optional[Annotated[int, Field(strict=True, ge=0)]] = 30
    invoice_footer: Optional[Annotated[str, Field(strict=True, max_length=1024)]] = None
    is_default: Optional[StrictBool] = False
    __properties: ClassVar[List[str]] = ["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"]

    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 BillingEntityCreate 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 BillingEntityCreate from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "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") if obj.get("currency") is not None else 'USD',
            "timezone": obj.get("timezone") if obj.get("timezone") is not None else 'UTC',
            "document_locale": obj.get("document_locale") if obj.get("document_locale") is not None else 'en',
            "invoice_prefix": obj.get("invoice_prefix"),
            "next_invoice_number": obj.get("next_invoice_number") if obj.get("next_invoice_number") is not None else 1,
            "invoice_grace_period": obj.get("invoice_grace_period") if obj.get("invoice_grace_period") is not None else 0,
            "net_payment_term": obj.get("net_payment_term") if obj.get("net_payment_term") is not None else 30,
            "invoice_footer": obj.get("invoice_footer"),
            "is_default": obj.get("is_default") if obj.get("is_default") is not None else False
        })
        return _obj


