import {
  portfolio,
  portfolioUsers,
  PortfolioGoal,
  PortfolioStatus,
  PortfolioRole,
} from "@/app/db/schema/portfolio";
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/app/db/db";
import { z } from "zod";

const createPortfolioSchema = z.object({
  userId: z.number(),
  portfolioName: z.string(),
  budget: z.number().optional(),
  goal: z.enum(PortfolioGoal),
  status: z.enum(PortfolioStatus),
  role: z.enum(PortfolioRole),
});

export async function POST(request: NextRequest) {
  const body = await request.json();
  return new NextResponse(JSON.stringify({ msg: "plan triggered" }), {
    status: 201,
  });

  //   try {
  //     const validatedBody = createPortfolioSchema.parse(body);
  //     const { userId, portfolioName, budget, goal, status, role } = validatedBody;

  //     const creationDate = new Date();

  //     const newPortfolio = await db
  //       .insert(portfolio)
  //       .values({
  //         name: portfolioName,
  //         budget: budget,
  //         goal: goal,
  //         status: status,
  //         createdAt: creationDate,
  //         updatedAt: creationDate,
  //       })
  //       .returning({ portfolioId: portfolio.id });

  //     const newPortfolioId = newPortfolio[0].portfolioId;

  //     const response = await db
  //       .insert(portfolioUsers)
  //       .values({ userId: userId, portfolioId: newPortfolioId, role: role })
  //       .returning();

  //     return new NextResponse(JSON.stringify(response), { status: 201 });
  //   } catch (error) {
  //     console.error(error);
  //     throw error;
  //   }
}
