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

from __future__ import annotations
from polar_sdk.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 OrganizationFeatureSettingsTypedDict(TypedDict):
    issue_funding_enabled: NotRequired[bool]
    r"""If this organization has issue funding enabled"""
    seat_based_pricing_enabled: NotRequired[bool]
    r"""If this organization has seat-based pricing enabled"""
    revops_enabled: NotRequired[bool]
    r"""If this organization has RevOps enabled"""
    wallets_enabled: NotRequired[bool]
    r"""If this organization has Wallets enabled"""
    member_model_enabled: NotRequired[bool]
    r"""If this organization has the Member model enabled"""
    tinybird_read: NotRequired[bool]
    r"""If this organization reads from Tinybird"""
    tinybird_compare: NotRequired[bool]
    r"""If this organization compares Tinybird results with database"""
    checkout_localization_enabled: NotRequired[bool]
    r"""If this organization has checkout localization enabled"""
    overview_metrics: NotRequired[Nullable[List[str]]]
    r"""Ordered list of metric slugs shown on the dashboard overview."""


class OrganizationFeatureSettings(BaseModel):
    issue_funding_enabled: Optional[bool] = False
    r"""If this organization has issue funding enabled"""

    seat_based_pricing_enabled: Optional[bool] = False
    r"""If this organization has seat-based pricing enabled"""

    revops_enabled: Optional[bool] = False
    r"""If this organization has RevOps enabled"""

    wallets_enabled: Optional[bool] = False
    r"""If this organization has Wallets enabled"""

    member_model_enabled: Optional[bool] = False
    r"""If this organization has the Member model enabled"""

    tinybird_read: Optional[bool] = False
    r"""If this organization reads from Tinybird"""

    tinybird_compare: Optional[bool] = False
    r"""If this organization compares Tinybird results with database"""

    checkout_localization_enabled: Optional[bool] = False
    r"""If this organization has checkout localization enabled"""

    overview_metrics: OptionalNullable[List[str]] = UNSET
    r"""Ordered list of metric slugs shown on the dashboard overview."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "issue_funding_enabled",
            "seat_based_pricing_enabled",
            "revops_enabled",
            "wallets_enabled",
            "member_model_enabled",
            "tinybird_read",
            "tinybird_compare",
            "checkout_localization_enabled",
            "overview_metrics",
        ]
        nullable_fields = ["overview_metrics"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(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
