# coding: utf-8

"""
    BeeL Public API

    Public invoicing API for self-employed professionals in Spain with full VeriFactu support.  **Authentication:** This API uses **API Keys** for authentication. Endpoints are designed for external integrations, automation, and programmatic access.  For browser-based authentication, use the Private API (with Session Cookies).  **Key Features:** - VeriFactu regulatory compliance - Complete invoice management (standard, corrective, simplified) - Customer management - Tax and invoice series configuration - PDF generation - Email sending - Duplicate prevention (idempotency)  **Idempotency:** Creation endpoints (POST) support the `Idempotency-Key` header to prevent duplicates in case of retries.  **Identifiers:** - All resources use UUIDs for technical identification - Invoice numbers are human-readable and searchable 

    The version of the OpenAPI document: 1.0.0
    Contact: it@beel.es
    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
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from beel_generated.models.equivalence_surcharge_percentage import EquivalenceSurchargePercentage
from beel_generated.models.irpf_percentage import IrpfPercentage
from beel_generated.models.payment_method import PaymentMethod
from beel_generated.models.tax_configuration_default_main_tax import TaxConfigurationDefaultMainTax
from typing import Optional, Set
from typing_extensions import Self

class TaxConfiguration(BaseModel):
    """
    TaxConfiguration
    """ # noqa: E501
    default_main_tax: TaxConfigurationDefaultMainTax
    apply_equivalence_surcharge: StrictBool = Field(description="Whether the freelancer is under the equivalence surcharge regime.  **Business rule**: If `true`, the `default_equivalence_surcharge` field is REQUIRED. ")
    default_equivalence_surcharge: Optional[EquivalenceSurchargePercentage] = Field(default=None, description="Default equivalence surcharge.  **Business rule**: REQUIRED if `apply_equivalence_surcharge` is `true`. ")
    apply_irpf: StrictBool = Field(description="Whether IRPF withholding should be applied to invoices.  **Business rule**: If `true` and `irpf_exempt` is `false`, the `default_irpf_rate` field is REQUIRED. ")
    default_irpf_rate: Optional[IrpfPercentage] = Field(default=None, description="Default IRPF for new invoices.  **Business rule**: REQUIRED if `apply_irpf` is `true` and `irpf_exempt` is `false`. ")
    irpf_exempt: Optional[StrictBool] = Field(default=False, description="Whether the freelancer is exempt from IRPF withholding (e.g., business start).  **Business rule**: If `true`, the `default_irpf_rate` field must be `null`. ")
    default_payment_method: Optional[PaymentMethod] = Field(default=None, description="Default payment method for new invoices. If NONE is selected, no payment information will be shown on the invoice. ")
    payment_term_days: Optional[Annotated[int, Field(le=365, strict=True, ge=0)]] = Field(default=None, description="Default payment term in days (0-365). Null means no default term.")
    __properties: ClassVar[List[str]] = ["default_main_tax", "apply_equivalence_surcharge", "default_equivalence_surcharge", "apply_irpf", "default_irpf_rate", "irpf_exempt", "default_payment_method", "payment_term_days"]

    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 TaxConfiguration 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 default_main_tax
        if self.default_main_tax:
            _dict['default_main_tax'] = self.default_main_tax.to_dict()
        # set to None if payment_term_days (nullable) is None
        # and model_fields_set contains the field
        if self.payment_term_days is None and "payment_term_days" in self.model_fields_set:
            _dict['payment_term_days'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "default_main_tax": TaxConfigurationDefaultMainTax.from_dict(obj["default_main_tax"]) if obj.get("default_main_tax") is not None else None,
            "apply_equivalence_surcharge": obj.get("apply_equivalence_surcharge") if obj.get("apply_equivalence_surcharge") is not None else False,
            "default_equivalence_surcharge": obj.get("default_equivalence_surcharge"),
            "apply_irpf": obj.get("apply_irpf") if obj.get("apply_irpf") is not None else True,
            "default_irpf_rate": obj.get("default_irpf_rate"),
            "irpf_exempt": obj.get("irpf_exempt") if obj.get("irpf_exempt") is not None else False,
            "default_payment_method": obj.get("default_payment_method"),
            "payment_term_days": obj.get("payment_term_days")
        })
        return _obj


