# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self

class CreateCompanyRequest(BaseModel):
    """
    CreateCompanyRequest
    """ # noqa: E501
    nif: StrictStr = Field(description="NIF/CIF of the business")
    legal_name: StrictStr = Field(description="Legal/fiscal name")
    entity_type: StrictStr = Field(description="Type of entity")
    address_street: StrictStr
    address_number: Optional[StrictStr] = None
    address_postal_code: StrictStr
    address_city: StrictStr
    address_province: StrictStr
    address_country: Optional[StrictStr] = 'ES'
    legal_form: Optional[StrictStr] = Field(default=None, description="Required for LEGAL_ENTITY")
    representative_name: Optional[StrictStr] = Field(default=None, description="Required for LEGAL_ENTITY")
    representative_nif: Optional[StrictStr] = Field(default=None, description="Required for LEGAL_ENTITY")
    business_display_name: Optional[StrictStr] = Field(default=None, description="Optional display name")
    tax_type: Optional[StrictStr] = 'IVA'
    tax_percentage: Optional[Union[StrictFloat, StrictInt]] = 21
    irpf_percentage: Optional[Union[StrictFloat, StrictInt]] = 15
    __properties: ClassVar[List[str]] = ["nif", "legal_name", "entity_type", "address_street", "address_number", "address_postal_code", "address_city", "address_province", "address_country", "legal_form", "representative_name", "representative_nif", "business_display_name", "tax_type", "tax_percentage", "irpf_percentage"]

    @field_validator('entity_type')
    def entity_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['INDIVIDUAL', 'LEGAL_ENTITY']):
            raise ValueError("must be one of enum values ('INDIVIDUAL', 'LEGAL_ENTITY')")
        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 CreateCompanyRequest 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "nif": obj.get("nif"),
            "legal_name": obj.get("legal_name"),
            "entity_type": obj.get("entity_type"),
            "address_street": obj.get("address_street"),
            "address_number": obj.get("address_number"),
            "address_postal_code": obj.get("address_postal_code"),
            "address_city": obj.get("address_city"),
            "address_province": obj.get("address_province"),
            "address_country": obj.get("address_country") if obj.get("address_country") is not None else 'ES',
            "legal_form": obj.get("legal_form"),
            "representative_name": obj.get("representative_name"),
            "representative_nif": obj.get("representative_nif"),
            "business_display_name": obj.get("business_display_name"),
            "tax_type": obj.get("tax_type") if obj.get("tax_type") is not None else 'IVA',
            "tax_percentage": obj.get("tax_percentage") if obj.get("tax_percentage") is not None else 21,
            "irpf_percentage": obj.get("irpf_percentage") if obj.get("irpf_percentage") is not None else 15
        })
        return _obj


