# ruff: noqa
# generated by datamodel-codegen:
#   filename:  https://api.glassflow.dev/v1/openapi.yaml
#   version:   0.27.2

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Literal, Optional, Union

from pydantic import BaseModel, ConfigDict, Field, RootModel


class Error(BaseModel):
    detail: str


class CreateOrganization(BaseModel):
    name: str


class Organization(CreateOrganization):
    id: str


class OrganizationScope(Organization):
    role: str


class OrganizationScopes(RootModel[list[OrganizationScope]]):
    root: list[OrganizationScope]


class SecretKey(RootModel[str]):
    root: str


class Type(str, Enum):
    organization = "organization"


class SecretRef(BaseModel):
    type: Type
    key: SecretKey


class CreateSecret(BaseModel):
    key: SecretKey
    value: str


class SignUp(BaseModel):
    access_token: str
    id_token: str


class BasePipeline(BaseModel):
    name: str
    space_id: str
    metadata: dict[str, Any]


class PipelineState(str, Enum):
    running = "running"
    paused = "paused"


class FunctionEnvironment(BaseModel):
    name: str
    value: str


class FunctionEnvironments(RootModel[Optional[list[FunctionEnvironment]]]):
    root: Optional[list[FunctionEnvironment]] = None


class Kind(str, Enum):
    google_pubsub = "google_pubsub"


class Config(BaseModel):
    project_id: str
    subscription_id: str
    credentials_json: str


class Kind1(str, Enum):
    amazon_sqs = "amazon_sqs"


class Config1(BaseModel):
    queue_url: str
    aws_region: str
    aws_access_key: str
    aws_secret_key: str


class Kind2(str, Enum):
    postgres = "postgres"


class Config2(BaseModel):
    db_host: str
    db_port: Optional[str] = "5432"
    db_user: str
    db_pass: str
    db_name: str
    db_sslmode: Optional[str] = None
    replication_slot: str
    publication: Optional[str] = None
    replication_output_plugin_name: Optional[str] = "wal2json"
    replication_output_plugin_args: Optional[list[str]] = None


class Kind3(str, Enum):
    webhook = "webhook"


class Method(str, Enum):
    get = "GET"
    post = "POST"
    put = "PUT"
    patch = "PATCH"
    delete = "DELETE"


class Header(BaseModel):
    name: str
    value: str


class Config3(BaseModel):
    url: str
    method: Method
    headers: list[Header]


class SinkConnectorWebhookConfigHeadersListItem(BaseModel):
    name: str
    value: str


class SinkConnectorWebhookConfigHeadersList(
    RootModel[list[SinkConnectorWebhookConfigHeadersListItem]]
):
    root: list[SinkConnectorWebhookConfigHeadersListItem]


class Kind4(str, Enum):
    clickhouse = "clickhouse"


class Config4(BaseModel):
    addr: str
    database: str
    username: str
    password: str
    table: str


class Kind5(str, Enum):
    amazon_s3 = "amazon_s3"


class Config5(BaseModel):
    s3_bucket: str
    s3_key: str
    aws_region: str
    aws_access_key: str
    aws_secret_key: str


class Kind6(str, Enum):
    snowflake_cdc_json = "snowflake_cdc_json"


class Config6(BaseModel):
    account: str
    warehouse: str
    db_user: str
    db_pass: str
    db_name: str
    db_schema: str
    db_host: Optional[str] = None
    db_port: Optional[str] = "443"
    db_role: Optional[str] = None


class Kind7(str, Enum):
    pinecone_json = "pinecone_json"


class ClientHeader(BaseModel):
    name: str
    value: str


class Config7(BaseModel):
    api_key: str
    api_host: str
    api_source_tag: Optional[str] = None
    index_host: str
    client_headers: Optional[list[ClientHeader]] = None


class Kind8(str, Enum):
    mongodb_json = "mongodb_json"


class Config8(BaseModel):
    connection_uri: str
    db_name: str


class Pipeline(BasePipeline):
    id: str
    created_at: datetime
    state: PipelineState


class SpacePipeline(Pipeline):
    space_name: str


class PipelineFunctionOutput(BaseModel):
    environments: FunctionEnvironments


class SpacePipelines(RootModel[list[SpacePipeline]]):
    root: list[SpacePipeline]


class CreateSpace(BaseModel):
    name: str


class UpdateSpace(BaseModel):
    name: str


class Space(CreateSpace):
    id: str
    created_at: datetime


class SpaceScope(Space):
    permission: str


class SpaceScopes(RootModel[list[SpaceScope]]):
    root: list[SpaceScope]


class Payload(BaseModel):
    model_config = ConfigDict(
        extra="allow",
    )
    message: str


class SeverityCodeInput(int, Enum):
    integer_100 = 100
    integer_200 = 200
    integer_400 = 400
    integer_500 = 500


class SeverityCode(RootModel[int]):
    root: int


class CreateAccessToken(BaseModel):
    name: str


class AccessToken(CreateAccessToken):
    id: str
    token: str
    created_at: datetime


class AccessTokens(RootModel[list[AccessToken]]):
    root: list[AccessToken]


class PaginationResponse(BaseModel):
    total_amount: int


class SourceFile(BaseModel):
    name: str
    content: str


class SourceFiles(RootModel[list[SourceFile]]):
    root: list[SourceFile]


class EventContext(BaseModel):
    request_id: str
    external_id: Optional[str] = None
    receive_time: datetime


class PersonalAccessToken(RootModel[str]):
    root: str


class QueryRangeMatrix(RootModel[Optional[Any]]):
    root: Optional[Any] = None


class ConnectorValueValue(BaseModel):
    value: str


class ConnectorValueSecretRef(BaseModel):
    secret_ref: SecretRef


class ConnectorValueList(RootModel[list[str]]):
    root: list[str]


class Profile(BaseModel):
    id: str
    home_organization: Organization
    name: str
    email: str
    provider: str
    external_settings: Any
    subscriber_id: str


class ListOrganizationScopes(PaginationResponse):
    organizations: OrganizationScopes


class Secret(BaseModel):
    key: SecretKey


class ListPipelines(PaginationResponse):
    pipelines: SpacePipelines


class ListSpaceScopes(PaginationResponse):
    spaces: SpaceScopes


class FunctionLogEntry(BaseModel):
    level: str
    severity_code: SeverityCode
    timestamp: datetime
    payload: Payload


class ListAccessTokens(PaginationResponse):
    access_tokens: AccessTokens


class ConsumeInputEvent(BaseModel):
    req_id: Optional[str] = Field(None, description="DEPRECATED")
    receive_time: Optional[datetime] = Field(None, description="DEPRECATED")
    payload: Any
    event_context: EventContext


class ConsumeOutputEvent(BaseModel):
    req_id: Optional[str] = Field(None, description="DEPRECATED")
    receive_time: Optional[datetime] = Field(None, description="DEPRECATED")
    payload: Any
    event_context: EventContext
    status: str
    response: Optional[Any] = None
    error_details: Optional[str] = None
    stack_trace: Optional[str] = None


class ListPersonalAccessTokens(BaseModel):
    tokens: list[PersonalAccessToken]


class PipelineInputQueueRelativeLatencyMetricsResponse(BaseModel):
    input_queue_total_push_events: QueryRangeMatrix
    input_queue_latency: QueryRangeMatrix


class ConnectorValue(RootModel[Union[ConnectorValueValue, ConnectorValueSecretRef]]):
    root: Union[ConnectorValueValue, ConnectorValueSecretRef]


class Secrets(RootModel[list[Secret]]):
    root: list[Secret]


class Configuration(BaseModel):
    project_id: ConnectorValue
    subscription_id: ConnectorValue
    credentials_json: ConnectorValue


class SourceConnectorGooglePubSub(BaseModel):
    kind: Literal["google_pubsub"]
    config: Optional[Config] = None
    configuration: Optional[Configuration] = None


class Configuration1(BaseModel):
    queue_url: ConnectorValue
    aws_region: ConnectorValue
    aws_access_key: ConnectorValue
    aws_secret_key: ConnectorValue


class SourceConnectorAmazonSQS(BaseModel):
    kind: Literal["amazon_sqs"]
    config: Optional[Config1] = None
    configuration: Optional[Configuration1] = None


class Configuration2(BaseModel):
    db_host: ConnectorValue
    db_port: Optional[ConnectorValue] = None
    db_user: ConnectorValue
    db_pass: ConnectorValue
    db_name: ConnectorValue
    db_sslmode: Optional[ConnectorValue] = None
    replication_slot: ConnectorValue
    publication: Optional[ConnectorValue] = None
    replication_output_plugin_name: Optional[ConnectorValue] = None
    replication_output_plugin_args: Optional[ConnectorValueList] = None


class SourceConnectorPostgres(BaseModel):
    kind: Literal["postgres"]
    config: Optional[Config2] = None
    configuration: Optional[Configuration2] = None


class Configuration3(BaseModel):
    url: ConnectorValue
    method: ConnectorValue
    headers: SinkConnectorWebhookConfigHeadersList


class SinkConnectorWebhook(BaseModel):
    kind: Literal["webhook"]
    config: Optional[Config3] = None
    configuration: Optional[Configuration3] = None


class Configuration4(BaseModel):
    addr: ConnectorValue
    database: ConnectorValue
    username: ConnectorValue
    password: ConnectorValue
    table: ConnectorValue


class SinkConnectorClickhouse(BaseModel):
    kind: Literal["clickhouse"]
    config: Optional[Config4] = None
    configuration: Optional[Configuration4] = None


class Configuration5(BaseModel):
    s3_bucket: ConnectorValue
    s3_key: ConnectorValue
    aws_region: ConnectorValue
    aws_access_key: ConnectorValue
    aws_secret_key: ConnectorValue


class SinkConnectorAmazonS3(BaseModel):
    kind: Literal["amazon_s3"]
    config: Optional[Config5] = None
    configuration: Optional[Configuration5] = None


class Configuration6(BaseModel):
    account: ConnectorValue
    warehouse: ConnectorValue
    db_user: ConnectorValue
    db_pass: ConnectorValue
    db_name: ConnectorValue
    db_schema: ConnectorValue
    db_host: Optional[ConnectorValue] = None
    db_port: Optional[ConnectorValue] = None
    db_role: Optional[ConnectorValue] = None


class SinkConnectorSnowflakeCDCJSON(BaseModel):
    kind: Literal["snowflake_cdc_json"]
    config: Optional[Config6] = None
    configuration: Optional[Configuration6] = None


class ClientHeader1(BaseModel):
    name: str
    value: ConnectorValue


class Configuration7(BaseModel):
    api_key: ConnectorValue
    api_host: ConnectorValue
    api_source_tag: Optional[ConnectorValue] = None
    index_host: ConnectorValue
    client_headers: Optional[list[ClientHeader1]] = None


class SinkConnectorPineconeJSON(BaseModel):
    kind: Literal["pinecone_json"]
    config: Optional[Config7] = None
    configuration: Optional[Configuration7] = None


class Configuration8(BaseModel):
    connection_uri: ConnectorValue
    db_name: ConnectorValue


class SinkConnectorMongoDBJSON(BaseModel):
    kind: Literal["mongodb_json"]
    config: Optional[Config8] = None
    configuration: Optional[Configuration8] = None


class FunctionLogs(RootModel[list[FunctionLogEntry]]):
    root: list[FunctionLogEntry]


class ListOrganizationSecrets(PaginationResponse):
    secrets: Secrets


class SourceConnector(
    RootModel[
        Optional[
            Union[
                SourceConnectorGooglePubSub,
                SourceConnectorAmazonSQS,
                SourceConnectorPostgres,
            ]
        ]
    ]
):
    root: Optional[
        Union[
            SourceConnectorGooglePubSub,
            SourceConnectorAmazonSQS,
            SourceConnectorPostgres,
        ]
    ] = Field(None, discriminator="kind")


class SinkConnector(
    RootModel[
        Optional[
            Union[
                SinkConnectorWebhook,
                SinkConnectorClickhouse,
                SinkConnectorAmazonS3,
                SinkConnectorSnowflakeCDCJSON,
                SinkConnectorPineconeJSON,
                SinkConnectorMongoDBJSON,
            ]
        ]
    ]
):
    root: Optional[
        Union[
            SinkConnectorWebhook,
            SinkConnectorClickhouse,
            SinkConnectorAmazonS3,
            SinkConnectorSnowflakeCDCJSON,
            SinkConnectorPineconeJSON,
            SinkConnectorMongoDBJSON,
        ]
    ] = Field(None, discriminator="kind")


class GetDetailedSpacePipeline(SpacePipeline):
    source_connector: SourceConnector
    sink_connector: SinkConnector
    environments: FunctionEnvironments


class UpdatePipeline(BaseModel):
    name: str
    transformation_function: Optional[str] = None
    transformation_requirements: Optional[list[str]] = None
    requirements_txt: Optional[str] = None
    metadata: Optional[dict[str, Any]] = None
    source_connector: Optional[SourceConnector] = None
    sink_connector: Optional[SinkConnector] = None
    environments: Optional[FunctionEnvironments] = None


class CreatePipeline(BasePipeline):
    transformation_function: Optional[str] = None
    transformation_requirements: Optional[list[str]] = None
    requirements_txt: Optional[str] = None
    source_connector: Optional[SourceConnector] = None
    sink_connector: Optional[SinkConnector] = None
    environments: Optional[FunctionEnvironments] = None
    state: Optional[PipelineState] = None
