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

from __future__ import annotations
from .v3_globaleventrules_ruleaction import (
    V3GlobalEventRulesRuleAction,
    V3GlobalEventRulesRuleActionTypedDict,
)
from datetime import datetime
from pydantic import model_serializer
from squadcast.types import BaseModel, UNSET_SENTINEL
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class V3GlobalEventRulesRulesetResponseTypedDict(TypedDict):
    id: NotRequired[int]
    global_event_rule_id: NotRequired[int]
    alert_source_shortname: NotRequired[str]
    alert_source_version: NotRequired[str]
    ordering: NotRequired[List[int]]
    catch_all_action: NotRequired[V3GlobalEventRulesRuleActionTypedDict]
    created_at: NotRequired[datetime]
    created_by: NotRequired[str]
    updated_at: NotRequired[datetime]
    updated_by: NotRequired[str]


class V3GlobalEventRulesRulesetResponse(BaseModel):
    id: Optional[int] = None

    global_event_rule_id: Optional[int] = None

    alert_source_shortname: Optional[str] = None

    alert_source_version: Optional[str] = None

    ordering: Optional[List[int]] = None

    catch_all_action: Optional[V3GlobalEventRulesRuleAction] = None

    created_at: Optional[datetime] = None

    created_by: Optional[str] = None

    updated_at: Optional[datetime] = None

    updated_by: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "id",
                "global_event_rule_id",
                "alert_source_shortname",
                "alert_source_version",
                "ordering",
                "catch_all_action",
                "created_at",
                "created_by",
                "updated_at",
                "updated_by",
            ]
        )
        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))

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

        return m
