"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.authRule = void 0;
const auth_1 = require("./auth");
function sanitizeRuleResponse(ruleResponse) {
    if (!ruleResponse.auth)
        ruleResponse.auth = {};
    return ruleResponse;
}
async function authSignUp(data, ruleResponse, authAdapter, databaseAdapter, context, options) {
    const signUpResponse = await (0, auth_1.signUp)(data, authAdapter, databaseAdapter, context, options);
    ruleResponse = sanitizeRuleResponse(ruleResponse);
    ruleResponse.auth.signUp = signUpResponse;
    return ruleResponse;
}
async function authSignIn(data, ruleResponse, authAdapter, context, options) {
    const signInResponse = await (0, auth_1.signIn)(data, authAdapter, context, options);
    ruleResponse = sanitizeRuleResponse(ruleResponse);
    ruleResponse.auth.signIn = signInResponse;
    return ruleResponse;
}
async function authRule(action, data, ruleResponse, authAdapter, databaseAdapter, context, options) {
    if (action === 'signUp')
        return authSignUp(data, ruleResponse, authAdapter, databaseAdapter, context, options);
    if (action === 'signIn')
        return authSignIn(data, ruleResponse, authAdapter, context, options);
    if (action === 'reset')
        throw { message: 'Reset not supported yet' };
}
exports.authRule = authRule;
