/*
  Warnings:

  - The values [WAITING_DISCOUNT_CODE] on the enum `TelegramSessionStep` will be removed. If these variants are still used in the database, this will fail.
  - The values [PLAN_PURCHASE,PLAN_RENEWAL,PLAN_UPGRADE,BOT_SUBSCRIPTION_PURCHASE,BOT_SUBSCRIPTION_RENEWAL] on the enum `TransactionType` will be removed. If these variants are still used in the database, this will fail.

*/
-- AlterEnum
BEGIN;
CREATE TYPE "TelegramSessionStep_new" AS ENUM ('IDLE', 'WAITING_CHANNEL_ADMIN_CONFIRM', 'WAITING_PLAN_TITLE', 'WAITING_PLAN_DURATION_UNIT', 'WAITING_PLAN_DURATION_VALUE', 'WAITING_PLAN_PRICE', 'WAITING_PLAN_EDIT_VALUE', 'WAITING_MEMBER_SEARCH_QUERY', 'WAITING_BOT_PLAN_TITLE', 'WAITING_BOT_PLAN_DURATION_UNIT', 'WAITING_BOT_PLAN_DURATION_VALUE', 'WAITING_BOT_PLAN_PRICE', 'WAITING_PAYMENT_RECEIPT', 'WAITING_REJECT_REASON', 'WAITING_NEW_DISCOUNT_CODE', 'WAITING_NEW_DISCOUNT_VALUE', 'WAITING_NEW_DISCOUNT_EXPIRY', 'WAITING_NEW_DISCOUNT_MAX_USAGE', 'WAITING_NEW_DISCOUNT_EXPIRY_DAYS', 'WAITING_BAN_DURATION_DAYS', 'WAITING_BAN_REASON', 'WAITING_ADMIN_USER_SEARCH_QUERY', 'WAITING_PLAN_CONFIRM', 'WAITING_BOT_PLAN_CONFIRM', 'WAITING_BROADCAST_CONTENT', 'WAITING_ADMIN_DISCOUNT_CODE', 'WAITING_ADMIN_DISCOUNT_VALUE', 'WAITING_ADMIN_DISCOUNT_MAX_USAGE', 'WAITING_ADMIN_DISCOUNT_EXPIRY_DAYS', 'WAITING_BANK_CARD_NUMBER', 'WAITING_BANK_CARD_HOLDER');
ALTER TABLE "public"."TelegramSession" ALTER COLUMN "step" DROP DEFAULT;
ALTER TABLE "TelegramSession" ALTER COLUMN "step" TYPE "TelegramSessionStep_new" USING ("step"::text::"TelegramSessionStep_new");
ALTER TYPE "TelegramSessionStep" RENAME TO "TelegramSessionStep_old";
ALTER TYPE "TelegramSessionStep_new" RENAME TO "TelegramSessionStep";
DROP TYPE "public"."TelegramSessionStep_old";
ALTER TABLE "TelegramSession" ALTER COLUMN "step" SET DEFAULT 'IDLE';
COMMIT;

-- AlterEnum
BEGIN;
CREATE TYPE "TransactionType_new" AS ENUM ('BOT_SUBSCRIPTION', 'CHANNEL_SUBSCRIPTION', 'REFUND', 'MANUAL_ADJUSTMENT');
ALTER TABLE "Transaction" ALTER COLUMN "type" TYPE "TransactionType_new" USING ("type"::text::"TransactionType_new");
ALTER TYPE "TransactionType" RENAME TO "TransactionType_old";
ALTER TYPE "TransactionType_new" RENAME TO "TransactionType";
DROP TYPE "public"."TransactionType_old";
COMMIT;

-- CreateTable
CREATE TABLE "ChannelMemberBan" (
    "id" TEXT NOT NULL,
    "channelId" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "reason" TEXT,
    "bannedUntil" TIMESTAMP(3),
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "ChannelMemberBan_channelId_idx" ON "ChannelMemberBan"("channelId");

-- CreateIndex
CREATE INDEX "ChannelMemberBan_userId_idx" ON "ChannelMemberBan"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "ChannelMemberBan_channelId_userId_key" ON "ChannelMemberBan"("channelId", "userId");

-- CreateIndex
CREATE INDEX "User_username_idx" ON "User"("username");

-- CreateIndex
CREATE INDEX "User_firstName_idx" ON "User"("firstName");

-- AddForeignKey
ALTER TABLE "ChannelMemberBan" ADD CONSTRAINT "ChannelMemberBan_channelId_fkey" FOREIGN KEY ("channelId") REFERENCES "Channel"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ChannelMemberBan" ADD CONSTRAINT "ChannelMemberBan_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
