-- CreateTable
CREATE TABLE "user_query_view" (
    "user_id" BIGINT NOT NULL,
    "account_sequence" VARCHAR(12) NOT NULL,
    "nickname" VARCHAR(100),
    "avatar_url" TEXT,
    "phone_number_masked" VARCHAR(20),
    "inviter_sequence" VARCHAR(12),
    "kyc_status" VARCHAR(20) NOT NULL DEFAULT 'NOT_VERIFIED',
    "personal_adoption_count" INTEGER NOT NULL DEFAULT 0,
    "team_address_count" INTEGER NOT NULL DEFAULT 0,
    "team_adoption_count" INTEGER NOT NULL DEFAULT 0,
    "province_adoption_count" INTEGER NOT NULL DEFAULT 0,
    "city_adoption_count" INTEGER NOT NULL DEFAULT 0,
    "leaderboard_rank" INTEGER,
    "status" VARCHAR(20) NOT NULL DEFAULT 'ACTIVE',
    "is_online" BOOLEAN NOT NULL DEFAULT false,
    "registered_at" TIMESTAMP(3) NOT NULL,
    "last_active_at" TIMESTAMP(3),
    "synced_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "user_query_view_pkey" PRIMARY KEY ("user_id")
);

-- CreateTable
CREATE TABLE "event_consumer_offsets" (
    "id" BIGSERIAL NOT NULL,
    "consumer_group" VARCHAR(100) NOT NULL,
    "topic" VARCHAR(100) NOT NULL,
    "partition" INTEGER NOT NULL,
    "offset" BIGINT NOT NULL,
    "updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "event_consumer_offsets_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "processed_events" (
    "id" BIGSERIAL NOT NULL,
    "event_id" VARCHAR(100) NOT NULL,
    "event_type" VARCHAR(50) NOT NULL,
    "processed_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "processed_events_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "user_query_view_account_sequence_key" ON "user_query_view"("account_sequence");

-- CreateIndex
CREATE INDEX "user_query_view_account_sequence_idx" ON "user_query_view"("account_sequence");

-- CreateIndex
CREATE INDEX "user_query_view_nickname_idx" ON "user_query_view"("nickname");

-- CreateIndex
CREATE INDEX "user_query_view_status_idx" ON "user_query_view"("status");

-- CreateIndex
CREATE INDEX "user_query_view_registered_at_idx" ON "user_query_view"("registered_at");

-- CreateIndex
CREATE INDEX "user_query_view_personal_adoption_count_idx" ON "user_query_view"("personal_adoption_count");

-- CreateIndex
CREATE INDEX "user_query_view_inviter_sequence_idx" ON "user_query_view"("inviter_sequence");

-- CreateIndex
CREATE UNIQUE INDEX "event_consumer_offsets_consumer_group_topic_partition_key" ON "event_consumer_offsets"("consumer_group", "topic", "partition");

-- CreateIndex
CREATE UNIQUE INDEX "processed_events_event_id_key" ON "processed_events"("event_id");

-- CreateIndex
CREATE INDEX "processed_events_event_type_idx" ON "processed_events"("event_type");

-- CreateIndex
CREATE INDEX "processed_events_processed_at_idx" ON "processed_events"("processed_at");
