# coding: utf-8

"""
    CATAPA API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0.0
    Contact: support@catapa.com
    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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from openapi_client.models.tax_dependent_request import TaxDependentRequest
from typing import Optional, Set
from typing_extensions import Self

class TaxMembershipTaxSubjectRequest(BaseModel):
    """
    TaxMembershipTaxSubjectRequest
    """ # noqa: E501
    npwp_address: StrictStr = Field(description="Address registered with NPWP", alias="npwpAddress")
    npwp_number: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="NPWP (Tax ID) number - can be empty or contain only digits", alias="npwpNumber")
    id_tku: Optional[StrictStr] = Field(default=None, description="TKU (Tax Knowledge Unit) identifier", alias="idTku")
    tin: Optional[StrictStr] = Field(default=None, description="Tax Identification Number")
    kpp_id: Optional[StrictStr] = Field(default=None, description="Tax office (KPP) identifier", alias="kppId")
    ptkp_category_id: Optional[StrictStr] = Field(default=None, description="PTKP (Personal Tax Free Income) category identifier", alias="ptkpCategoryId")
    tax_dependents: Optional[List[TaxDependentRequest]] = Field(default=None, description="List of tax dependents for PTKP calculation", alias="taxDependents")
    __properties: ClassVar[List[str]] = ["npwpAddress", "npwpNumber", "idTku", "tin", "kppId", "ptkpCategoryId", "taxDependents"]

    @field_validator('npwp_number')
    def npwp_number_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^$|^\d+$", value):
            raise ValueError(r"must validate the regular expression /^$|^\d+$/")
        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 TaxMembershipTaxSubjectRequest 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 tax_dependents (list)
        _items = []
        if self.tax_dependents:
            for _item_tax_dependents in self.tax_dependents:
                if _item_tax_dependents:
                    _items.append(_item_tax_dependents.to_dict())
            _dict['taxDependents'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "npwpAddress": obj.get("npwpAddress"),
            "npwpNumber": obj.get("npwpNumber"),
            "idTku": obj.get("idTku"),
            "tin": obj.get("tin"),
            "kppId": obj.get("kppId"),
            "ptkpCategoryId": obj.get("ptkpCategoryId"),
            "taxDependents": [TaxDependentRequest.from_dict(_item) for _item in obj["taxDependents"]] if obj.get("taxDependents") is not None else None
        })
        return _obj


