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

from __future__ import annotations
from ascend_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from datetime import datetime
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class FileTypedDict(TypedDict):
    r"""The file containing the snapshot data."""

    download_uri: NotRequired[str]
    r"""The signed download uri for the file."""
    uri_expiry_time: NotRequired[Nullable[datetime]]
    r"""The timestamp at which the download uri expires."""


class File(BaseModel):
    r"""The file containing the snapshot data."""

    download_uri: Optional[str] = None
    r"""The signed download uri for the file."""

    uri_expiry_time: OptionalNullable[datetime] = UNSET
    r"""The timestamp at which the download uri expires."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["download_uri", "uri_expiry_time"]
        nullable_fields = ["uri_expiry_time"]
        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


class SnapshotProcessDateTypedDict(TypedDict):
    r"""The process date of the snapshot."""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class SnapshotProcessDate(BaseModel):
    r"""The process date of the snapshot."""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class SnapshotTypedDict(TypedDict):
    r"""A snapshot containing the snapshot information and a file download link."""

    create_time: NotRequired[Nullable[datetime]]
    r"""The timestamp at which the snapshot was created at."""
    file: NotRequired[Nullable[FileTypedDict]]
    r"""The file containing the snapshot data."""
    name: NotRequired[str]
    r"""The name of the resource."""
    process_date: NotRequired[Nullable[SnapshotProcessDateTypedDict]]
    r"""The process date of the snapshot."""
    snapshot_id: NotRequired[str]
    r"""Unique id of the snapshot file."""
    snapshot_type: NotRequired[str]
    r"""The type of the snapshot."""
    version: NotRequired[str]
    r"""The version of the snapshot."""


class Snapshot(BaseModel):
    r"""A snapshot containing the snapshot information and a file download link."""

    create_time: OptionalNullable[datetime] = UNSET
    r"""The timestamp at which the snapshot was created at."""

    file: OptionalNullable[File] = UNSET
    r"""The file containing the snapshot data."""

    name: Optional[str] = None
    r"""The name of the resource."""

    process_date: OptionalNullable[SnapshotProcessDate] = UNSET
    r"""The process date of the snapshot."""

    snapshot_id: Optional[str] = None
    r"""Unique id of the snapshot file."""

    snapshot_type: Optional[str] = None
    r"""The type of the snapshot."""

    version: Optional[str] = None
    r"""The version of the snapshot."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "create_time",
            "file",
            "name",
            "process_date",
            "snapshot_id",
            "snapshot_type",
            "version",
        ]
        nullable_fields = ["create_time", "file", "process_date"]
        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
