-- ======================
-- CRM: Deal
-- ======================
CREATE TABLE "unified_crm_deal" (
  "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,
  "name"                   VARCHAR,
  "amount"                 FLOAT,
  "currency"               VARCHAR,
  "closed_at"              TIMESTAMP_NTZ,
  "closing_at"             TIMESTAMP_NTZ,
  "stage"                  VARCHAR,
  "stage_id"               VARCHAR,
  "pipeline"               VARCHAR,
  "pipeline_id"            VARCHAR,
  "stages"                 VARIANT,
  "pipelines"              VARIANT,
  "source"                 VARCHAR,
  "probability"            FLOAT,
  "tags"                   VARIANT,
  "lost_reason"            VARCHAR,
  "won_reason"             VARCHAR,
  "user_id"                VARCHAR,
  "contact_ids"            VARIANT,
  "company_ids"            VARIANT,
  "metadata"               VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- CRM: Contact
-- ======================
CREATE TABLE "unified_crm_contact" (
  "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,
  "name"                   VARCHAR,
  "first_name"             VARCHAR,
  "last_name"              VARCHAR,
  "title"                  VARCHAR,
  "company"                VARCHAR,
  "emails"                 VARIANT,
  "telephones"             VARIANT,
  "deal_ids"               VARIANT,
  "company_ids"            VARIANT,
  "address"                VARIANT,
  "user_id"                VARCHAR,
  "link_urls"              VARIANT,
  "metadata"               VARIANT,
  "department"             VARCHAR,
  "image_url"              VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- CRM: Company
-- ======================
CREATE TABLE "unified_crm_company" (
  "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,
  "name"                   VARCHAR,
  "deal_ids"               VARIANT,
  "contact_ids"            VARIANT,
  "emails"                 VARIANT,
  "telephones"             VARIANT,
  "websites"               VARIANT,
  "address"                VARIANT,
  "is_active"              BOOLEAN,
  "tags"                   VARIANT,
  "description"            VARCHAR,
  "industry"               VARCHAR,
  "link_urls"              VARIANT,
  "employees"              FLOAT,
  "timezone"               VARCHAR,
  "user_id"                VARCHAR,
  "metadata"               VARIANT,
  "domains"                VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- CRM: Event
-- ======================
CREATE TABLE "unified_crm_event" (
  "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,
  "type"                   VARCHAR,
  "note"                   VARIANT,
  "meeting"                VARIANT,
  "email"                  VARIANT,
  "call"                   VARIANT,
  "task"                   VARIANT,
  "marketing_email"        VARIANT,
  "form"                   VARIANT,
  "page_view"              VARIANT,
  "deal_ids"               VARIANT,
  "company_ids"            VARIANT,
  "contact_ids"            VARIANT,
  "lead_ids"               VARIANT,
  "user_id"                VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- CRM: Lead
-- ======================
CREATE TABLE "unified_crm_lead" (
  "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,
  "name"                   VARCHAR,
  "first_name"             VARCHAR,
  "last_name"              VARCHAR,
  "user_id"                VARCHAR,
  "creator_user_id"        VARCHAR,
  "contact_id"             VARCHAR,
  "company_id"             VARCHAR,
  "company_name"           VARCHAR,
  "is_active"              BOOLEAN,
  "address"                VARIANT,
  "emails"                 VARIANT,
  "telephones"             VARIANT,
  "source"                 VARCHAR,
  "status"                 VARCHAR,
  "link_urls"              VARIANT,
  "metadata"               VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- CRM: Picklist
-- ======================
CREATE TABLE "unified_crm_picklist" (
  "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,
  "name"                   VARCHAR,
  "label"                  VARCHAR,
  "type"                   VARCHAR,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
-- ======================
-- CRM: Pipeline
-- ======================
CREATE TABLE "unified_crm_pipeline" (
  "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,
  "name"                   VARCHAR,
  "is_active"              BOOLEAN,
  "deal_probability"       FLOAT,
  "display_order"          FLOAT,
  "stages"                 VARIANT,
  "raw"                    VARIANT,
  UNIQUE ("unified_connection_id", "unified_id")
);
