-- ======================
-- PAYMENT: Payment
-- ======================
CREATE TABLE "unified_payment_payment" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "total_amount"           FLOAT,
  "contact_id"             VARCHAR,
  "payment_method"         VARCHAR,
  "type"                   VARCHAR,
  "currency"               VARCHAR,
  "notes"                  VARCHAR,
  "invoice_id"             VARCHAR,
  "bill_id"                VARCHAR,
  "link_id"                VARCHAR,
  "account_id"             VARCHAR,
  "reference"              VARCHAR,
  "organization_id"        VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- PAYMENT: Link
-- ======================
CREATE TABLE "unified_payment_link" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "is_active"              BOOLEAN,
  "lineitems"              VARIANT,
  "currency"               VARCHAR,
  "amount"                 FLOAT,
  "payment_id"             VARCHAR,
  "contact_id"             VARCHAR,
  "url"                    VARCHAR,
  "is_chargeable_now"      BOOLEAN,
  "success_url"            VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- PAYMENT: Refund
-- ======================
CREATE TABLE "unified_payment_refund" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "total_amount"           FLOAT,
  "payment_id"             VARCHAR,
  "currency"               VARCHAR,
  "notes"                  VARCHAR,
  "status"                 VARCHAR,
  "reference"              VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- PAYMENT: Payout
-- ======================
CREATE TABLE "unified_payment_payout" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             VARCHAR,
  "updated_at"             VARCHAR,
  "total_amount"           FLOAT,
  "currency"               VARCHAR,
  "notes"                  VARCHAR,
  "status"                 VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- PAYMENT: Subscription
-- ======================
CREATE TABLE "unified_payment_subscription" (
  "unified_connection_id"  VARCHAR NOT NULL,
  "unified_webhook_id"     VARCHAR NOT NULL,
  "unified_external_xref"  VARCHAR,
  "unified_integration_type" VARCHAR NOT NULL,
  "unified_raw_id"         VARCHAR,
  "unified_id"             VARCHAR NOT NULL,
  "id"                     VARCHAR,
  "created_at"             TIMESTAMP_NTZ,
  "updated_at"             TIMESTAMP_NTZ,
  "description"            VARCHAR,
  "contact_id"             VARCHAR,
  "invoice_id"             VARCHAR,
  "current_period_end_at"  TIMESTAMP_NTZ,
  "current_period_start_at" TIMESTAMP_NTZ,
  "canceled_at"            TIMESTAMP_NTZ,
  "currency"               VARCHAR,
  "start_at"               TIMESTAMP_NTZ,
  "end_at"                 TIMESTAMP_NTZ,
  "status"                 VARCHAR,
  "month"                  FLOAT,
  "interval_unit"          VARCHAR,
  "day_of_month"           FLOAT,
  "day_of_week"            FLOAT,
  "interval"               FLOAT,
  "lineitems"              VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
