CREATE TYPE "BudgetReleaseNotifyTarget" AS ENUM ('ALL_GROUP_USERS', 'GROUP_MEMBERS_ONLY');

ALTER TABLE "app_settings"
  ADD COLUMN "required_approval_types" "ApprovalType"[] NOT NULL DEFAULT ARRAY['CHAIR_A', 'CHAIR_B', 'FINANCE']::"ApprovalType"[],
  ADD COLUMN "budget_release_notify_target" "BudgetReleaseNotifyTarget" NOT NULL DEFAULT 'ALL_GROUP_USERS';

CREATE TABLE "expense_documents" (
  "id" TEXT NOT NULL,
  "expense_id" TEXT NOT NULL,
  "invoice_date" TIMESTAMP(3) NOT NULL,
  "proof_url" TEXT NOT NULL,
  "drive_file_id" TEXT,
  "original_file_name" TEXT NOT NULL,
  "stored_file_name" TEXT NOT NULL,
  "mime_type" TEXT NOT NULL,
  "size" INTEGER NOT NULL,
  "uploaded_by_id" TEXT NOT NULL,
  "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CONSTRAINT "expense_documents_pkey" PRIMARY KEY ("id")
);

CREATE INDEX "expense_documents_expense_id_idx" ON "expense_documents"("expense_id");
CREATE INDEX "expense_documents_uploaded_by_id_idx" ON "expense_documents"("uploaded_by_id");

ALTER TABLE "expense_documents"
  ADD CONSTRAINT "expense_documents_expense_id_fkey"
  FOREIGN KEY ("expense_id") REFERENCES "expenses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE "expense_documents"
  ADD CONSTRAINT "expense_documents_uploaded_by_id_fkey"
  FOREIGN KEY ("uploaded_by_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

ALTER TABLE "expenses"
  DROP COLUMN "invoice_date",
  DROP COLUMN "proof_url";
