"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .payment_method_bank_account import (
    PaymentMethodBankAccount,
    PaymentMethodBankAccountTypedDict,
)
from enum import Enum
from gusto_embedded.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class ContractorPaymentMethodType(str, Enum):
    r"""The payment method type. If type is Check, then split_by and splits do not need to be populated. If type is Direct Deposit, split_by and splits are required."""

    DIRECT_DEPOSIT = "Direct Deposit"
    CHECK = "Check"


class ContractorPaymentMethodSplitBy(str, Enum):
    r"""Describes how the payment will be split. If split_by is Percentage, then the split amounts must add up to exactly 100. If split_by is Amount, then the last split amount must be nil to capture the remainder."""

    AMOUNT = "Amount"
    PERCENTAGE = "Percentage"


class ContractorPaymentMethodTypedDict(TypedDict):
    r"""Example response"""

    version: NotRequired[str]
    r"""The current version of the object. See the [versioning guide](https://docs.gusto.com/embedded-payroll/docs/idempotency) for information on how to use this field."""
    type: NotRequired[ContractorPaymentMethodType]
    r"""The payment method type. If type is Check, then split_by and splits do not need to be populated. If type is Direct Deposit, split_by and splits are required."""
    split_by: NotRequired[Nullable[ContractorPaymentMethodSplitBy]]
    r"""Describes how the payment will be split. If split_by is Percentage, then the split amounts must add up to exactly 100. If split_by is Amount, then the last split amount must be nil to capture the remainder."""
    splits: NotRequired[Nullable[List[PaymentMethodBankAccountTypedDict]]]


class ContractorPaymentMethod(BaseModel):
    r"""Example response"""

    version: Optional[str] = None
    r"""The current version of the object. See the [versioning guide](https://docs.gusto.com/embedded-payroll/docs/idempotency) for information on how to use this field."""

    type: Optional[ContractorPaymentMethodType] = None
    r"""The payment method type. If type is Check, then split_by and splits do not need to be populated. If type is Direct Deposit, split_by and splits are required."""

    split_by: OptionalNullable[ContractorPaymentMethodSplitBy] = UNSET
    r"""Describes how the payment will be split. If split_by is Percentage, then the split amounts must add up to exactly 100. If split_by is Amount, then the last split amount must be nil to capture the remainder."""

    splits: OptionalNullable[List[PaymentMethodBankAccount]] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["version", "type", "split_by", "splits"]
        nullable_fields = ["split_by", "splits"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
