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

from __future__ import annotations
from .v3_services_jiraissuetype import (
    V3ServicesJiraIssueType,
    V3ServicesJiraIssueTypeTypedDict,
)
from .v3_services_jiraproject import (
    V3ServicesJiraProject,
    V3ServicesJiraProjectTypedDict,
)
from .v3_services_jirastatusmap import (
    V3ServicesJiraStatusMap,
    V3ServicesJiraStatusMapTypedDict,
)
from pydantic import model_serializer
from squadcast.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from typing import List
from typing_extensions import NotRequired, TypedDict


class V3ServicesJiraCloudExtensionTypedDict(TypedDict):
    jira_client_key: str
    project: V3ServicesJiraProjectTypedDict
    issue_type: V3ServicesJiraIssueTypeTypedDict
    is_manual: bool
    statusmaps: NotRequired[Nullable[List[V3ServicesJiraStatusMapTypedDict]]]


class V3ServicesJiraCloudExtension(BaseModel):
    jira_client_key: str

    project: V3ServicesJiraProject

    issue_type: V3ServicesJiraIssueType

    is_manual: bool

    statusmaps: OptionalNullable[List[V3ServicesJiraStatusMap]] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["statusmaps"])
        nullable_fields = set(["statusmaps"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m
