# 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, StrictFloat, StrictInt
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from beel_generated.models.invoice_totals_surcharge_breakdown_inner import InvoiceTotalsSurchargeBreakdownInner
from beel_generated.models.invoice_totals_vat_breakdown_inner import InvoiceTotalsVatBreakdownInner
from typing import Optional, Set
from typing_extensions import Self

class InvoiceTotals(BaseModel):
    """
    InvoiceTotals
    """ # noqa: E501
    taxable_base: Union[StrictFloat, StrictInt] = Field(description="Total taxable base (can be negative in corrective invoices)")
    total_discounts: Optional[Union[Annotated[float, Field(strict=True, ge=0)], Annotated[int, Field(strict=True, ge=0)]]] = 0
    vat_breakdown: Optional[List[InvoiceTotalsVatBreakdownInner]] = None
    total_vat: Union[StrictFloat, StrictInt] = Field(description="Total VAT (can be negative in corrective invoices)")
    surcharge_breakdown: Optional[List[InvoiceTotalsSurchargeBreakdownInner]] = None
    total_equivalence_surcharge: Union[StrictFloat, StrictInt] = Field(description="Total equivalence surcharge (can be negative in corrective invoices)")
    irpf_breakdown: Optional[List[InvoiceTotalsSurchargeBreakdownInner]] = None
    total_irpf: Union[StrictFloat, StrictInt] = Field(description="Total personal income tax withheld (can be negative in corrective invoices)")
    invoice_total: Union[StrictFloat, StrictInt] = Field(description="Total amount to pay (base + VAT + RE - IRPF, can be negative in corrective invoices)")
    __properties: ClassVar[List[str]] = ["taxable_base", "total_discounts", "vat_breakdown", "total_vat", "surcharge_breakdown", "total_equivalence_surcharge", "irpf_breakdown", "total_irpf", "invoice_total"]

    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 InvoiceTotals 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 each item in vat_breakdown (list)
        _items = []
        if self.vat_breakdown:
            for _item_vat_breakdown in self.vat_breakdown:
                if _item_vat_breakdown:
                    _items.append(_item_vat_breakdown.to_dict())
            _dict['vat_breakdown'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in surcharge_breakdown (list)
        _items = []
        if self.surcharge_breakdown:
            for _item_surcharge_breakdown in self.surcharge_breakdown:
                if _item_surcharge_breakdown:
                    _items.append(_item_surcharge_breakdown.to_dict())
            _dict['surcharge_breakdown'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in irpf_breakdown (list)
        _items = []
        if self.irpf_breakdown:
            for _item_irpf_breakdown in self.irpf_breakdown:
                if _item_irpf_breakdown:
                    _items.append(_item_irpf_breakdown.to_dict())
            _dict['irpf_breakdown'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "taxable_base": obj.get("taxable_base"),
            "total_discounts": obj.get("total_discounts") if obj.get("total_discounts") is not None else 0,
            "vat_breakdown": [InvoiceTotalsVatBreakdownInner.from_dict(_item) for _item in obj["vat_breakdown"]] if obj.get("vat_breakdown") is not None else None,
            "total_vat": obj.get("total_vat"),
            "surcharge_breakdown": [InvoiceTotalsSurchargeBreakdownInner.from_dict(_item) for _item in obj["surcharge_breakdown"]] if obj.get("surcharge_breakdown") is not None else None,
            "total_equivalence_surcharge": obj.get("total_equivalence_surcharge") if obj.get("total_equivalence_surcharge") is not None else 0,
            "irpf_breakdown": [InvoiceTotalsSurchargeBreakdownInner.from_dict(_item) for _item in obj["irpf_breakdown"]] if obj.get("irpf_breakdown") is not None else None,
            "total_irpf": obj.get("total_irpf") if obj.get("total_irpf") is not None else 0,
            "invoice_total": obj.get("invoice_total")
        })
        return _obj


