-- CreateTable: pending_rewards
-- 待领取奖励表，逐笔记录每笔待领取奖励，支持独立过期时间

CREATE TABLE "pending_rewards" (
    "pending_reward_id" BIGSERIAL NOT NULL,
    "account_sequence" VARCHAR(20) NOT NULL,
    "user_id" BIGINT NOT NULL,
    "usdt_amount" DECIMAL(20,8) NOT NULL,
    "hashpower_amount" DECIMAL(20,8) NOT NULL,
    "source_order_id" VARCHAR(100) NOT NULL,
    "allocation_type" VARCHAR(50) NOT NULL,
    "expire_at" TIMESTAMP(3) NOT NULL,
    "status" VARCHAR(20) NOT NULL DEFAULT 'PENDING',
    "settled_at" TIMESTAMP(3),
    "expired_at" TIMESTAMP(3),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "pending_rewards_pkey" PRIMARY KEY ("pending_reward_id")
);

-- CreateIndex
CREATE INDEX "pending_rewards_account_sequence_status_idx" ON "pending_rewards"("account_sequence", "status");

-- CreateIndex
CREATE INDEX "pending_rewards_user_id_status_idx" ON "pending_rewards"("user_id", "status");

-- CreateIndex: 用于定时任务查询过期奖励
CREATE INDEX "pending_rewards_status_expire_at_idx" ON "pending_rewards"("status", "expire_at");

-- CreateIndex
CREATE INDEX "pending_rewards_source_order_id_idx" ON "pending_rewards"("source_order_id");

-- CreateIndex
CREATE INDEX "pending_rewards_created_at_idx" ON "pending_rewards"("created_at");
