/*
  Warnings:

  - You are about to drop the column `currency` on the `trades` table. All the data in the column will be lost.
  - You are about to drop the column `trading_account_id` on the `trades` table. All the data in the column will be lost.
  - You are about to drop the column `default_currency` on the `trading_accounts` table. All the data in the column will be lost.
  - You are about to drop the `trading_account_balance` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `trading_account_transactions` table. If the table is not empty, all the data it contains will be lost.
  - Added the required column `trading_wallet_id` to the `trades` table without a default value. This is not possible if the table is not empty.

*/
-- CreateEnum
CREATE TYPE "TradingWalletTransactionType" AS ENUM ('DEPOSIT', 'WITHDRAW', 'WIN', 'LOSS');

-- DropForeignKey
ALTER TABLE "trades" DROP CONSTRAINT "trades_trading_account_id_fkey";

-- DropForeignKey
ALTER TABLE "trading_account_balance" DROP CONSTRAINT "trading_account_balance_tradingAccountId_fkey";

-- DropForeignKey
ALTER TABLE "trading_account_transactions" DROP CONSTRAINT "trading_account_transactions_trading_account_id_fkey";

-- AlterTable
ALTER TABLE "trades" DROP COLUMN "currency",
DROP COLUMN "trading_account_id",
ADD COLUMN     "trading_wallet_id" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "trading_accounts" DROP COLUMN "default_currency";

-- DropTable
DROP TABLE "trading_account_balance";

-- DropTable
DROP TABLE "trading_account_transactions";

-- DropEnum
DROP TYPE "TradingAccountTransactionType";

-- CreateTable
CREATE TABLE "trading_wallets" (
    "id" TEXT NOT NULL,
    "trading_account_id" TEXT NOT NULL,
    "currency" TEXT NOT NULL,
    "default" BOOLEAN NOT NULL DEFAULT false,
    "initial_balance" DOUBLE PRECISION NOT NULL,
    "current_balance" DOUBLE PRECISION NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "trading_wallet_transactions" (
    "id" TEXT NOT NULL,
    "trading_wallet_id" TEXT NOT NULL,
    "type" "TradingWalletTransactionType" NOT NULL,
    "amount" DOUBLE PRECISION NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- AddForeignKey
ALTER TABLE "trading_wallets" ADD CONSTRAINT "trading_wallets_trading_account_id_fkey" FOREIGN KEY ("trading_account_id") REFERENCES "trading_accounts"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "trading_wallet_transactions" ADD CONSTRAINT "trading_wallet_transactions_trading_wallet_id_fkey" FOREIGN KEY ("trading_wallet_id") REFERENCES "trading_wallets"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "trades" ADD CONSTRAINT "trades_trading_wallet_id_fkey" FOREIGN KEY ("trading_wallet_id") REFERENCES "trading_wallets"("id") ON DELETE CASCADE ON UPDATE CASCADE;
