/*
  Warnings:

  - The values [Reference] on the enum `PerkType` will be removed. If these variants are still used in the database, this will fail.
  - You are about to drop the column `type` on the `PerkDefinition` table. All the data in the column will be lost.
  - You are about to drop the column `type` on the `PerkInstance` table. All the data in the column will be lost.
  - You are about to drop the column `type` on the `PerkTemplate` table. All the data in the column will be lost.

*/
-- CreateEnum
CREATE TYPE "PayPeriod" AS ENUM ('Hourly', 'Daily', 'Weekly', 'BiWeekly', 'SemiMonthly', 'Monthly', 'Quarterly', 'Yearly', 'Fixed');

-- CreateEnum
CREATE TYPE "MemberPaycheckModelName" AS ENUM ('MemberPaycheck');

-- AlterTable
ALTER TABLE "PerkDefinition" DROP COLUMN "type";

-- AlterTable
ALTER TABLE "PerkInstance" DROP COLUMN "type";

-- AlterTable
ALTER TABLE "PerkTemplate" DROP COLUMN "type";

-- AlterEnum
BEGIN;
CREATE TYPE "PerkType_new" AS ENUM ('Message', 'Badge', 'EarnedWageAccess');
ALTER TYPE "PerkType" RENAME TO "PerkType_old";
ALTER TYPE "PerkType_new" RENAME TO "PerkType";
DROP TYPE "PerkType_old";
COMMIT;

-- AlterTable
ALTER TABLE "Member" ADD COLUMN     "netPay" INTEGER,
ADD COLUMN     "payPeriod" "PayPeriod";

-- AlterTable
ALTER TABLE "Organization" ADD COLUMN     "directDepositSubstring" TEXT NOT NULL DEFAULT E'';

-- CreateTable
CREATE TABLE "MemberPaycheck" (
    "modelName" "MemberPaycheckModelName" NOT NULL DEFAULT E'MemberPaycheck',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "netPay" INTEGER NOT NULL,
    "hours" DOUBLE PRECISION,
    "startAt" DATE NOT NULL,
    "endAt" DATE NOT NULL,
    "memberId" UUID NOT NULL,
    "payrollProviderId" UUID NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,
    "externalServiceType" "ExternalServiceType",
    "externalServiceId" TEXT NOT NULL DEFAULT E'',

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

-- AddForeignKey
ALTER TABLE "MemberPaycheck" ADD CONSTRAINT "MemberPaycheck_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberPaycheck" ADD CONSTRAINT "MemberPaycheck_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberPaycheck" ADD CONSTRAINT "MemberPaycheck_payrollProviderId_fkey" FOREIGN KEY ("payrollProviderId") REFERENCES "PayrollProvider"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
