import { FastifyReply, FastifyRequest } from "fastify";
import prisma from "../../utils/prisma";
import {
  BusinessPlanSchema,
  MarketResearchSchema,
  NetworkingSchema,
  ProspectingSchema,
  SourcingSchema,
} from "./schema";

// ------------------------------------------------------------------------------------

export async function createBusinessPlan(
  req: FastifyRequest<{
    Body: BusinessPlanSchema;
  }>,
  reply: FastifyReply
) {
  const data = req.body;

  await prisma.businessPlan.create({
    data: {
      firstName: data.firstName,
      lastName: data.lastName,
      nationality: data.nationality,
      phoneNumber: data.phoneNumber,
      email: data.email.toLowerCase(),
      projectIdea: data.projectIdea,
      location: data.location,
      educationAndExperience: data.educationAndExperience,
      financingPlan: data.financingPlan,
    },
  });
  return reply.code(200).send({ message: "success" });
}

// ------------------------------------------------------------------------------------

export async function createMarketResearch(
  req: FastifyRequest<{
    Body: MarketResearchSchema;
  }>,
  reply: FastifyReply
) {
  const data = req.body;

  await prisma.marketResearch.create({
    data: {
      firstName: data.firstName,
      lastName: data.lastName,
      phoneNumber: data.phoneNumber,
      email: data.email.toLowerCase(),
      address: data.address,
      city: data.city,
      state: data.state,
      zipCode: data.zipCode,
      country: data.country,
      projectIdea: data.projectIdea,
      educationAndExperience: data.educationAndExperience,
    },
  });
  return reply.code(200).send({ message: "success" });
}

// ------------------------------------------------------------------------------------

export async function createNetworking(
  req: FastifyRequest<{
    Body: NetworkingSchema;
  }>,
  reply: FastifyReply
) {
  const data = req.body;

  await prisma.networking.create({
    data: {
      firstName: data.firstName,
      lastName: data.lastName,
      phoneNumber: data.phoneNumber,
      email: data.email.toLowerCase(),
      activity: data.activity,
      needForNetworking: data.needForNetworking,
    },
  });
  return reply.code(200).send({ message: "success" });
}

// ------------------------------------------------------------------------------------

export async function createSourcing(
  req: FastifyRequest<{
    Body: SourcingSchema;
  }>,
  reply: FastifyReply
) {
  const data = req.body;

  await prisma.sourcing.create({
    data: {
      firstName: data.firstName,
      lastName: data.lastName,
      phoneNumber: data.phoneNumber,
      email: data.email.toLowerCase(),
      activity: data.activity,
      productsToSource: data.productsToSource,
    },
  });
  return reply.code(200).send({ message: "success" });
}

// ------------------------------------------------------------------------------------

export async function createProspecting(
  req: FastifyRequest<{
    Body: ProspectingSchema;
  }>,
  reply: FastifyReply
) {
  const data = req.body;

  await prisma.prospecting.create({
    data: {
      firstName: data.firstName,
      lastName: data.lastName,
      phoneNumber: data.phoneNumber,
      email: data.email.toLowerCase(),
      activity: data.activity,
      needForProspecting: data.needForProspecting,
    },
  });
  return reply.code(200).send({ message: "success" });
}

// ------------------------------------------------------------------------------------
