-- CreateTable
CREATE TABLE "payment_methods" (
    "id" BIGSERIAL NOT NULL,
    "method_type" VARCHAR(20) NOT NULL,
    "bank_name" VARCHAR(128),
    "account_holder" VARCHAR(128),
    "account_number" VARCHAR(128),
    "usdt_address" VARCHAR(256),
    "qr_code_url" VARCHAR(500),
    "display_name" VARCHAR(128),
    "sort_order" INTEGER NOT NULL DEFAULT 0,
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "show_on_player" BOOLEAN NOT NULL DEFAULT true,
    "created_by" BIGINT,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "deposit_orders" (
    "id" BIGSERIAL NOT NULL,
    "order_no" VARCHAR(64) NOT NULL,
    "player_id" BIGINT NOT NULL,
    "payment_method_id" BIGINT NOT NULL,
    "method_type" VARCHAR(20) NOT NULL,
    "amount" DECIMAL(18,4) NOT NULL,
    "screenshot_url" VARCHAR(500) NOT NULL,
    "status" VARCHAR(20) NOT NULL DEFAULT 'PENDING',
    "approved_amount" DECIMAL(18,4),
    "reviewer_id" BIGINT,
    "reviewed_at" TIMESTAMP(3),
    "reject_reason" VARCHAR(500),
    "remark" VARCHAR(500),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "payment_methods_method_type_is_active_idx" ON "payment_methods"("method_type", "is_active");

-- CreateIndex
CREATE UNIQUE INDEX "deposit_orders_order_no_key" ON "deposit_orders"("order_no");

-- CreateIndex
CREATE INDEX "deposit_orders_player_id_idx" ON "deposit_orders"("player_id");

-- CreateIndex
CREATE INDEX "deposit_orders_status_idx" ON "deposit_orders"("status");

-- CreateIndex
CREATE INDEX "deposit_orders_created_at_idx" ON "deposit_orders"("created_at");

-- AddForeignKey
ALTER TABLE "deposit_orders" ADD CONSTRAINT "deposit_orders_player_id_fkey" FOREIGN KEY ("player_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "deposit_orders" ADD CONSTRAINT "deposit_orders_payment_method_id_fkey" FOREIGN KEY ("payment_method_id") REFERENCES "payment_methods"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
