"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.getPresentation = getPresentation;
exports.editPresentation = editPresentation;
exports.getTermsOfService = getTermsOfService;
exports.editTermsOfService = editTermsOfService;
exports.getPrivacyPolicy = getPrivacyPolicy;
exports.editPrivacyPolicy = editPrivacyPolicy;
const prisma_1 = __importDefault(require("../../utils/prisma"));
// ------------------------------------------------------------------------------------
function getPresentation(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const ccis = yield prisma_1.default.ccis.findFirst();
        if (ccis) {
            return reply.code(200).send({ presentation: ccis.presentation });
        }
        return reply.code(200).send({ presentation: "" });
    });
}
function editPresentation(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = req.body;
        const ccis = yield prisma_1.default.ccis.findFirst();
        if (ccis) {
            const newCcis = yield prisma_1.default.ccis.update({
                where: {
                    id: ccis.id,
                },
                data: {
                    presentation: data.presenation,
                },
            });
            return reply.code(200).send(newCcis);
        }
        const newCcis = yield prisma_1.default.ccis.create({
            data: {
                presentation: data.presenation,
                privacyPolicy: "",
                termsOfService: "",
            },
        });
        return reply.code(200).send({ presentation: newCcis.presentation });
    });
}
// ------------------------------------------------------------------------------------
function getTermsOfService(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const ccis = yield prisma_1.default.ccis.findFirst();
        if (ccis) {
            return reply.code(200).send({ termsOfService: ccis.termsOfService });
        }
        return reply.code(200).send({ termsOfService: "" });
    });
}
function editTermsOfService(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = req.body;
        const ccis = yield prisma_1.default.ccis.findFirst();
        if (ccis) {
            const newCcis = yield prisma_1.default.ccis.update({
                where: {
                    id: ccis.id,
                },
                data: {
                    termsOfService: data.termsOfService,
                },
            });
            return reply.code(200).send(newCcis);
        }
        const newCcis = yield prisma_1.default.ccis.create({
            data: {
                termsOfService: data.termsOfService,
                privacyPolicy: "",
                presentation: "",
            },
        });
        return reply.code(200).send({ termsOfService: newCcis.termsOfService });
    });
}
// ------------------------------------------------------------------------------------
function getPrivacyPolicy(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const ccis = yield prisma_1.default.ccis.findFirst();
        if (ccis) {
            return reply.code(200).send({ privacyPolicy: ccis.privacyPolicy });
        }
        return reply.code(200).send({ privacyPolicy: "" });
    });
}
function editPrivacyPolicy(req, reply) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = req.body;
        const ccis = yield prisma_1.default.ccis.findFirst();
        if (ccis) {
            const newCcis = yield prisma_1.default.ccis.update({
                where: {
                    id: ccis.id,
                },
                data: {
                    privacyPolicy: data.privacyPolicy,
                },
            });
            return reply.code(200).send(newCcis);
        }
        const newCcis = yield prisma_1.default.ccis.create({
            data: {
                privacyPolicy: data.privacyPolicy,
                presentation: "",
                termsOfService: "",
            },
        });
        return reply.code(200).send({ privacyPolicy: newCcis.privacyPolicy });
    });
}
