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

from __future__ import annotations
from .resourcestatus import ResourceStatus
from apideck_unify import models
from apideck_unify.types import BaseModel
from apideck_unify.utils import validate_open_enum
from pydantic import field_serializer
from pydantic.functional_validators import PlainValidator
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class LinkedConnectorResourceTypedDict(TypedDict):
    id: NotRequired[str]
    r"""ID of the resource, typically a lowercased version of name."""
    name: NotRequired[str]
    r"""Name of the resource (plural)"""
    status: NotRequired[ResourceStatus]
    r"""Status of the resource. Resources with status live or beta are callable."""
    downstream_id: NotRequired[str]
    r"""ID of the resource in the Connector's API (downstream)"""
    downstream_name: NotRequired[str]
    r"""Name of the resource in the Connector's API (downstream)"""


class LinkedConnectorResource(BaseModel):
    id: Optional[str] = None
    r"""ID of the resource, typically a lowercased version of name."""

    name: Optional[str] = None
    r"""Name of the resource (plural)"""

    status: Annotated[
        Optional[ResourceStatus], PlainValidator(validate_open_enum(False))
    ] = None
    r"""Status of the resource. Resources with status live or beta are callable."""

    downstream_id: Optional[str] = None
    r"""ID of the resource in the Connector's API (downstream)"""

    downstream_name: Optional[str] = None
    r"""Name of the resource in the Connector's API (downstream)"""

    @field_serializer("status")
    def serialize_status(self, value):
        if isinstance(value, str):
            try:
                return models.ResourceStatus(value)
            except ValueError:
                return value
        return value
