# 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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from openapi_client.models.tax_dependent_response import TaxDependentResponse
from openapi_client.models.tax_membership_period_response import TaxMembershipPeriodResponse
from typing import Optional, Set
from typing_extensions import Self

class TaxMembershipResponse(BaseModel):
    """
    TaxMembershipResponse
    """ # noqa: E501
    id: StrictStr = Field(description="Unique identifier for the tax membership")
    foreign_tax_object: StrictBool = Field(description="Whether this is a foreign tax object", alias="foreignTaxObject")
    kpp_id: StrictStr = Field(description="Tax office (KPP) identifier", alias="kppId")
    link_to_payroll: StrictBool = Field(description="Whether this tax membership is linked to payroll", alias="linkToPayroll")
    membership_end_period: TaxMembershipPeriodResponse = Field(alias="membershipEndPeriod")
    membership_start_period: TaxMembershipPeriodResponse = Field(alias="membershipStartPeriod")
    effective_end_period: Optional[TaxMembershipPeriodResponse] = Field(default=None, alias="effectiveEndPeriod")
    effective_start_period: Optional[TaxMembershipPeriodResponse] = Field(default=None, alias="effectiveStartPeriod")
    method: StrictStr = Field(description="PPh21 calculation method")
    more_than_one_employer: StrictBool = Field(description="Whether employee has more than one employer", alias="moreThanOneEmployer")
    npwp_address: StrictStr = Field(description="Address registered with NPWP", alias="npwpAddress")
    npwp_number: Annotated[str, Field(strict=True)] = Field(description="NPWP (Tax ID) number - can be empty or contain only digits", alias="npwpNumber")
    tin: Optional[StrictStr] = Field(default=None, description="Tax Identification Number")
    previous_net_income: Union[Annotated[float, Field(strict=True, ge=0)], Annotated[int, Field(strict=True, ge=0)]] = Field(description="Previous net income amount", alias="previousNetIncome")
    previous_paid_pph: Union[Annotated[float, Field(strict=True, ge=0)], Annotated[int, Field(strict=True, ge=0)]] = Field(description="Previous paid PPh amount", alias="previousPaidPph")
    ptkp_category_id: StrictStr = Field(description="PTKP (Personal Tax Free Income) category identifier", alias="ptkpCategoryId")
    tax_object: StrictStr = Field(description="Type of tax object for the employee", alias="taxObject")
    use_recommended_period: Optional[StrictBool] = Field(default=None, alias="useRecommendedPeriod")
    tax_dependents: Optional[List[TaxDependentResponse]] = Field(default=None, description="List of tax dependents for PTKP calculation", alias="taxDependents")
    __properties: ClassVar[List[str]] = ["id", "foreignTaxObject", "kppId", "linkToPayroll", "membershipEndPeriod", "membershipStartPeriod", "effectiveEndPeriod", "effectiveStartPeriod", "method", "moreThanOneEmployer", "npwpAddress", "npwpNumber", "tin", "previousNetIncome", "previousPaidPph", "ptkpCategoryId", "taxObject", "useRecommendedPeriod", "taxDependents"]

    @field_validator('method')
    def method_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['GROSS', 'NETTO', 'GROSS_UP', 'MIX', 'MIX_GROSS_NETTO', 'MIX_NETTO_GROSS', 'MIX_GROSS_UP_GROSS']):
            raise ValueError("must be one of enum values ('GROSS', 'NETTO', 'GROSS_UP', 'MIX', 'MIX_GROSS_NETTO', 'MIX_NETTO_GROSS', 'MIX_GROSS_UP_GROSS')")
        return value

    @field_validator('npwp_number')
    def npwp_number_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^$|^\d+$", value):
            raise ValueError(r"must validate the regular expression /^$|^\d+$/")
        return value

    @field_validator('tax_object')
    def tax_object_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['PERMANENT', 'TEMPORARY', 'MULTI_LEVEL_DISTRIBUTOR', 'INSURANCE_AGENT', 'MERCHANT_GOODS', 'EXPERT_CONTINUOUS', 'EXPERT_NON_CONTINUOUS', 'CONTINUOUS', 'NON_CONTINUOUS', 'COMMISSIONER', 'FORMER_EMPLOYEE', 'EVENT_PARTICIPANT', 'EXPATRIATE', 'EXPERT', 'MEETING_PARTICIPANT', 'COMMITTEE_PARTICIPANT', 'EDUCATION_PARTICIPANT', 'OTHER_PARTICIPANT', 'ADVISOR_LECTURER', 'AUTHOR_RESEARCHER', 'SERVICE_PROVIDER', 'ADVERTISING_AGENT', 'PROJECT_MANAGER', 'INTERMEDIARY', 'ARTIST', 'ATHLETE', 'TEMPORARY_MONTHLY', 'COMPETITION_PARTICIPANT']):
            raise ValueError("must be one of enum values ('PERMANENT', 'TEMPORARY', 'MULTI_LEVEL_DISTRIBUTOR', 'INSURANCE_AGENT', 'MERCHANT_GOODS', 'EXPERT_CONTINUOUS', 'EXPERT_NON_CONTINUOUS', 'CONTINUOUS', 'NON_CONTINUOUS', 'COMMISSIONER', 'FORMER_EMPLOYEE', 'EVENT_PARTICIPANT', 'EXPATRIATE', 'EXPERT', 'MEETING_PARTICIPANT', 'COMMITTEE_PARTICIPANT', 'EDUCATION_PARTICIPANT', 'OTHER_PARTICIPANT', 'ADVISOR_LECTURER', 'AUTHOR_RESEARCHER', 'SERVICE_PROVIDER', 'ADVERTISING_AGENT', 'PROJECT_MANAGER', 'INTERMEDIARY', 'ARTIST', 'ATHLETE', 'TEMPORARY_MONTHLY', 'COMPETITION_PARTICIPANT')")
        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 TaxMembershipResponse 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 membership_end_period
        if self.membership_end_period:
            _dict['membershipEndPeriod'] = self.membership_end_period.to_dict()
        # override the default output from pydantic by calling `to_dict()` of membership_start_period
        if self.membership_start_period:
            _dict['membershipStartPeriod'] = self.membership_start_period.to_dict()
        # override the default output from pydantic by calling `to_dict()` of effective_end_period
        if self.effective_end_period:
            _dict['effectiveEndPeriod'] = self.effective_end_period.to_dict()
        # override the default output from pydantic by calling `to_dict()` of effective_start_period
        if self.effective_start_period:
            _dict['effectiveStartPeriod'] = self.effective_start_period.to_dict()
        # 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 TaxMembershipResponse from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "foreignTaxObject": obj.get("foreignTaxObject"),
            "kppId": obj.get("kppId"),
            "linkToPayroll": obj.get("linkToPayroll"),
            "membershipEndPeriod": TaxMembershipPeriodResponse.from_dict(obj["membershipEndPeriod"]) if obj.get("membershipEndPeriod") is not None else None,
            "membershipStartPeriod": TaxMembershipPeriodResponse.from_dict(obj["membershipStartPeriod"]) if obj.get("membershipStartPeriod") is not None else None,
            "effectiveEndPeriod": TaxMembershipPeriodResponse.from_dict(obj["effectiveEndPeriod"]) if obj.get("effectiveEndPeriod") is not None else None,
            "effectiveStartPeriod": TaxMembershipPeriodResponse.from_dict(obj["effectiveStartPeriod"]) if obj.get("effectiveStartPeriod") is not None else None,
            "method": obj.get("method"),
            "moreThanOneEmployer": obj.get("moreThanOneEmployer"),
            "npwpAddress": obj.get("npwpAddress"),
            "npwpNumber": obj.get("npwpNumber"),
            "tin": obj.get("tin"),
            "previousNetIncome": obj.get("previousNetIncome"),
            "previousPaidPph": obj.get("previousPaidPph"),
            "ptkpCategoryId": obj.get("ptkpCategoryId"),
            "taxObject": obj.get("taxObject"),
            "useRecommendedPeriod": obj.get("useRecommendedPeriod"),
            "taxDependents": [TaxDependentResponse.from_dict(_item) for _item in obj["taxDependents"]] if obj.get("taxDependents") is not None else None
        })
        return _obj


