-- CreateTable
CREATE TABLE "player_message_broadcasts" (
    "id" BIGSERIAL NOT NULL,
    "title" VARCHAR(256) NOT NULL,
    "body" TEXT NOT NULL,
    "target_type" VARCHAR(16) NOT NULL,
    "target_user_id" BIGINT,
    "target_username" VARCHAR(64),
    "recipient_count" INTEGER NOT NULL DEFAULT 0,
    "created_by_id" BIGINT,
    "created_by_username" VARCHAR(64),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- AlterTable
ALTER TABLE "player_messages" ADD COLUMN "broadcast_id" BIGINT;

-- CreateIndex
CREATE INDEX "player_message_broadcasts_created_at_idx" ON "player_message_broadcasts"("created_at" DESC);

-- CreateIndex
CREATE INDEX "player_messages_broadcast_id_idx" ON "player_messages"("broadcast_id");

-- AddForeignKey
ALTER TABLE "player_messages" ADD CONSTRAINT "player_messages_broadcast_id_fkey" FOREIGN KEY ("broadcast_id") REFERENCES "player_message_broadcasts"("id") ON DELETE CASCADE ON UPDATE CASCADE;
