# 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 datetime import date
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from openapi_client.models.bank_account_configuration_request import BankAccountConfigurationRequest
from openapi_client.models.id_request import IdRequest
from typing import Optional, Set
from typing_extensions import Self

class UpdateBankAccountConfigurationRequest(BaseModel):
    """
    UpdateBankAccountConfigurationRequest
    """ # noqa: E501
    employee: Optional[IdRequest] = None
    effective_date: Optional[date] = Field(default=None, description="YYYY-MM-DD", alias="effectiveDate")
    payment_method: StrictStr = Field(alias="paymentMethod")
    distribution_method: Optional[StrictStr] = Field(default=None, alias="distributionMethod")
    bank_accounts: Optional[List[BankAccountConfigurationRequest]] = Field(default=None, alias="bankAccounts")
    source: Optional[IdRequest] = None
    __properties: ClassVar[List[str]] = ["employee", "effectiveDate", "paymentMethod", "distributionMethod", "bankAccounts", "source"]

    @field_validator('payment_method')
    def payment_method_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['TRANSFER', 'CASH']):
            raise ValueError("must be one of enum values ('TRANSFER', 'CASH')")
        return value

    @field_validator('distribution_method')
    def distribution_method_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['PERCENTAGE', 'FIXED_AMOUNT']):
            raise ValueError("must be one of enum values ('PERCENTAGE', 'FIXED_AMOUNT')")
        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 UpdateBankAccountConfigurationRequest 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 employee
        if self.employee:
            _dict['employee'] = self.employee.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in bank_accounts (list)
        _items = []
        if self.bank_accounts:
            for _item_bank_accounts in self.bank_accounts:
                if _item_bank_accounts:
                    _items.append(_item_bank_accounts.to_dict())
            _dict['bankAccounts'] = _items
        # override the default output from pydantic by calling `to_dict()` of source
        if self.source:
            _dict['source'] = self.source.to_dict()
        # set to None if distribution_method (nullable) is None
        # and model_fields_set contains the field
        if self.distribution_method is None and "distribution_method" in self.model_fields_set:
            _dict['distributionMethod'] = None

        # set to None if bank_accounts (nullable) is None
        # and model_fields_set contains the field
        if self.bank_accounts is None and "bank_accounts" in self.model_fields_set:
            _dict['bankAccounts'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "employee": IdRequest.from_dict(obj["employee"]) if obj.get("employee") is not None else None,
            "effectiveDate": obj.get("effectiveDate"),
            "paymentMethod": obj.get("paymentMethod"),
            "distributionMethod": obj.get("distributionMethod"),
            "bankAccounts": [BankAccountConfigurationRequest.from_dict(_item) for _item in obj["bankAccounts"]] if obj.get("bankAccounts") is not None else None,
            "source": IdRequest.from_dict(obj["source"]) if obj.get("source") is not None else None
        })
        return _obj


