//! Outbound gateway webhooks: persistent definitions, event catalogs, and dispatch runtime.
//!
//! This crate owns the reusable webhook domain so `athena_rs` can keep a thin
//! compatibility facade while the implementation lives in a publishable
//! workspace crate.
//!
//! With the following routes, non-gateway aliases will be deprecated in Athena
//! `4.x.x`.
//!
//! - `ROUTE_GATEWAY_DATA`: Awaiting deprecation
//! - `ROUTE_GATEWAY_FETCH`: Latest
//! - `ROUTE_GATEWAY_UPDATE`: Latest
//! - `ROUTE_GATEWAY_QUERY`: Will get more narrow permissions and tighter restrictions to be possible to be exposed
//! - `ROUTE_GATEWAY_INSERT`: Latest
//! - `ROUTE_GATEWAY_DELETE`: Has gotten changes in how `resource_id` is used
//! - `ROUTE_REST_GET`: AWAITING DEPRECATION
//! - `ROUTE_REST_POST`: AWAITING DEPRECATION
//! - `ROUTE_REST_PATCH`: AWAITING DEPRECATION
//! - `ROUTE_REST_DELETE`: AWAITING DEPRECATION
//!
//! ## Deprecation of the `ROUTE_REST_*`
//! These aliases were carried over from earlier PostgREST support. The gateway
//! can now stand on its own, so the direct gateway route keys are the long-term
//! surface.
//!
//! This means the gateway request object can eventually inherit the originating
//! request type directly instead of duplicating route-key aliases.
//!
//! WebRequest -> GatewayRequest -> WebRequest::RequestType
//!
//!
//! We borrow the trade from the WebRequest which is WebRequest::RequestType

pub mod catalog;
mod dispatch;
mod error_codes;
pub mod inbound;
pub mod schema;
mod sink_dispatch;
pub mod sinks;
pub mod store;

pub use catalog::{GatewayWebhookEventDescriptor, gateway_webhook_event_catalog};
pub use dispatch::{
    GatewayWebhookTrigger, WebhookRuntime, dispatch_webhook_test,
    gateway_webhook_trigger_from_http, spawn_gateway_webhook_dispatch,
};
pub use error_codes::{
    WEBHOOK_ERROR_CODE_WEBHOOK_NOT_FOUND, WEBHOOK_ERROR_CODE_WEBHOOK_SINK_NOT_FOUND,
    WEBHOOK_ERROR_CODE_WEBHOOK_SINK_PROVISION_FAILED, WEBHOOK_PUBLIC_ERROR_CODES,
    WebhookPublicErrorCode,
};
pub use inbound::{
    InboundWebhookBillingEnrichmentDefinition, InboundWebhookSinkDefinition,
    InboundWebhookSinkPayload, InboundWebhookSinkRuntimeContext, build_default_inbound_sink_row,
    build_projected_inbound_sink_rows, default_secret_header_name, default_secret_query_param,
    json_pointer_string, load_inbound_sink_registry_from_path, qualify_webhook_sink_table_name,
    resolve_inbound_selector_string, resolve_inbound_selector_value,
    resolve_inbound_sink_client_name, summary_from_inbound_sink,
};
pub use sink_dispatch::{
    dispatch_webhook_sink_test, dispatch_webhook_sink_test_by_id,
    spawn_gateway_webhook_sink_dispatch,
};

pub use schema::{
    ROUTE_SCHEMA_COLUMN_ADDED, ROUTE_SCHEMA_COLUMN_ALTERED, ROUTE_SCHEMA_COLUMN_DROPPED,
    ROUTE_SCHEMA_COLUMN_RENAMED, ROUTE_SCHEMA_EXTENSION_INSTALLED, ROUTE_SCHEMA_INDEX_CREATED,
    ROUTE_SCHEMA_INDEX_DROPPED, ROUTE_SCHEMA_TABLE_CREATED, ROUTE_SCHEMA_TABLE_DROPPED,
    ROUTE_SCHEMA_VIEW_CREATED, ROUTE_SCHEMA_VIEW_DROPPED,
};

// TODO: I think a global catalog here would be more in place
pub const ROUTE_GATEWAY_DATA: &str = "gateway_data";
pub const ROUTE_GATEWAY_FETCH: &str = "gateway_fetch";
pub const ROUTE_GATEWAY_UPDATE: &str = "gateway_update";
pub const ROUTE_GATEWAY_QUERY: &str = "gateway_query";
pub const ROUTE_GATEWAY_INSERT: &str = "gateway_insert";
pub const ROUTE_GATEWAY_DELETE: &str = "gateway_delete";
pub const ROUTE_BILLING_DOCUMENT_UPSERTED: &str = "billing_document_upserted";
pub const ROUTE_REST_GET: &str = "rest_get";
pub const ROUTE_REST_POST: &str = "rest_post";
pub const ROUTE_REST_PATCH: &str = "rest_patch";
pub const ROUTE_REST_DELETE: &str = "rest_delete";
