"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.settingsCreate = settingsCreate;
exports.settingsGet = settingsGet;
exports.settingsGetItem = settingsGetItem;
exports.settingsSetItem = settingsSetItem;
exports.settingsDeleteItem = settingsDeleteItem;
const settings_1 = require("../components/settings");
const utils_1 = require("../utils");
function sendResponse(_req, res, data) {
    return res.set('content-type', 'application/json').status(200).send(JSON.stringify(data));
}
function settingsCreate(req, res) {
    const { ctx, params: { username, ytAuthCluster }, } = req;
    return (0, settings_1.create)({ ctx, username, cluster: ytAuthCluster })
        .then(sendResponse.bind(null, req, res))
        .catch(utils_1.sendError.bind(null, res));
}
function settingsGet(req, res) {
    const { ctx, params: { username, ytAuthCluster }, } = req;
    return (0, settings_1.get)({ ctx, username, cluster: ytAuthCluster })
        .then(sendResponse.bind(null, req, res))
        .catch(utils_1.sendError.bind(null, res));
}
async function settingsGetItem(req, res) {
    const { ctx, params: { username, path, ytAuthCluster }, } = req;
    return (0, settings_1.getItem)({ ctx, username, path, cluster: ytAuthCluster })
        .then(sendResponse.bind(null, req, res))
        .catch(utils_1.sendError.bind(null, res));
}
function settingsSetItem(req, res) {
    const { ctx, params: { username, path, ytAuthCluster }, body: { value } = {}, } = req;
    return (0, settings_1.setItem)({ ctx, username, path, value, cluster: ytAuthCluster })
        .then(sendResponse.bind(null, req, res))
        .catch(utils_1.sendError.bind(null, res));
}
function settingsDeleteItem(req, res) {
    const { ctx, params: { username, path, ytAuthCluster }, } = req;
    return (0, settings_1.deleteItem)({ ctx, username, path, cluster: ytAuthCluster })
        .then(sendResponse.bind(null, req, res))
        .catch(utils_1.sendError.bind(null, res));
}
