/*
  Warnings:

  - The `is_admin_paid_payment_to_supplier` column on the `tbl_order` table would be dropped and recreated. This will lead to data loss if there is data in the column.

*/
-- CreateEnum
CREATE TYPE "payoutStatus" AS ENUM ('pending', 'failed', 'success');

-- CreateEnum
CREATE TYPE "sellerPayoutStatus" AS ENUM ('unpaid', 'paid', 'half_paid');

-- AlterTable
ALTER TABLE "tbl_order" DROP COLUMN "is_admin_paid_payment_to_supplier",
ADD COLUMN     "is_admin_paid_payment_to_supplier" "sellerPayoutStatus" DEFAULT 'unpaid';

-- CreateTable
CREATE TABLE "tbl_order_payout" (
    "id" BIGSERIAL NOT NULL,
    "supplier_id" BIGINT NOT NULL,
    "order_id" BIGINT NOT NULL,
    "currency" VARCHAR(64),
    "currency_symbol" VARCHAR(16),
    "amount" DECIMAL(13,2),
    "payout_at" TIMESTAMP(3),
    "payout_status" "payoutStatus" DEFAULT 'pending',
    "inserted_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3),

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

-- CreateIndex
CREATE INDEX "tbl_order_payout_supplier_id_order_id_currency_currency_sym_idx" ON "tbl_order_payout"("supplier_id", "order_id", "currency", "currency_symbol", "amount", "payout_at");

-- AddForeignKey
ALTER TABLE "tbl_order_payout" ADD CONSTRAINT "tbl_order_payout_supplier_id_fkey" FOREIGN KEY ("supplier_id") REFERENCES "tbl_user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tbl_order_payout" ADD CONSTRAINT "tbl_order_payout_order_id_fkey" FOREIGN KEY ("order_id") REFERENCES "tbl_order"("id") ON DELETE CASCADE ON UPDATE CASCADE;
