"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBusinessPlan = getBusinessPlan;
exports.deleteBusinessPlan = deleteBusinessPlan;
exports.getMarketResearch = getMarketResearch;
exports.deleteMarketResearch = deleteMarketResearch;
exports.getNetworking = getNetworking;
exports.deleteNetworking = deleteNetworking;
exports.getSourcing = getSourcing;
exports.deleteSourcing = deleteSourcing;
exports.getProspecting = getProspecting;
exports.deleteProspecting = deleteProspecting;
const prisma_1 = __importDefault(require("../../utils/prisma"));
// ------------------------------------------------------------------------------------
function getBusinessPlan(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = yield prisma_1.default.businessPlan.findMany();
        return reply.code(200).send(data);
    });
}
function deleteBusinessPlan(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const id = req.params.id;
        const item = yield prisma_1.default.businessPlan.findUnique({
            where: {
                id: id,
            },
        });
        if (!item) {
            return reply.code(404).send({
                message: "Élément n'existe pas",
            });
        }
        try {
            yield prisma_1.default.businessPlan.delete({
                where: { id: id },
            });
        }
        catch (_a) {
            return reply.code(400).send({
                message: "Vous ne pouvez pas supprimer cet élément",
            });
        }
        return reply.code(200).send({});
    });
}
// ------------------------------------------------------------------------------------
function getMarketResearch(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = yield prisma_1.default.marketResearch.findMany();
        return reply.code(200).send(data);
    });
}
function deleteMarketResearch(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const id = req.params.id;
        const item = yield prisma_1.default.marketResearch.findUnique({
            where: {
                id: id,
            },
        });
        if (!item) {
            return reply.code(404).send({
                message: "Élément n'existe pas",
            });
        }
        try {
            yield prisma_1.default.marketResearch.delete({
                where: { id: id },
            });
        }
        catch (_a) {
            return reply.code(400).send({
                message: "Vous ne pouvez pas supprimer cet élément",
            });
        }
        return reply.code(200).send({});
    });
}
// ------------------------------------------------------------------------------------
function getNetworking(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = yield prisma_1.default.networking.findMany();
        return reply.code(200).send(data);
    });
}
function deleteNetworking(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const id = req.params.id;
        const item = yield prisma_1.default.networking.findUnique({
            where: {
                id: id,
            },
        });
        if (!item) {
            return reply.code(404).send({
                message: "Élément n'existe pas",
            });
        }
        try {
            yield prisma_1.default.networking.delete({
                where: { id: id },
            });
        }
        catch (_a) {
            return reply.code(400).send({
                message: "Vous ne pouvez pas supprimer cet élément",
            });
        }
        return reply.code(200).send({});
    });
}
// ------------------------------------------------------------------------------------
function getSourcing(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = yield prisma_1.default.sourcing.findMany();
        return reply.code(200).send(data);
    });
}
function deleteSourcing(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const id = req.params.id;
        const item = yield prisma_1.default.sourcing.findUnique({
            where: {
                id: id,
            },
        });
        if (!item) {
            return reply.code(404).send({
                message: "Élément n'existe pas",
            });
        }
        try {
            yield prisma_1.default.sourcing.delete({
                where: { id: id },
            });
        }
        catch (_a) {
            return reply.code(400).send({
                message: "Vous ne pouvez pas supprimer cet élément",
            });
        }
        return reply.code(200).send({});
    });
}
// ------------------------------------------------------------------------------------
function getProspecting(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = yield prisma_1.default.prospecting.findMany();
        return reply.code(200).send(data);
    });
}
function deleteProspecting(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const id = req.params.id;
        const item = yield prisma_1.default.prospecting.findUnique({
            where: {
                id: id,
            },
        });
        if (!item) {
            return reply.code(404).send({
                message: "Élément n'existe pas",
            });
        }
        try {
            yield prisma_1.default.prospecting.delete({
                where: { id: id },
            });
        }
        catch (_a) {
            return reply.code(400).send({
                message: "Vous ne pouvez pas supprimer cet élément",
            });
        }
        return reply.code(200).send({});
    });
}
// ------------------------------------------------------------------------------------
