
const routePOST = (router, path, handler) => {
    router.route(path)
    .post(handler)
    .get(methodNotAllowed)
    .put(methodNotAllowed)
    .delete(methodNotAllowed)
    .patch(methodNotAllowed)
    .options(methodNotAllowed)
    .head(methodNotAllowed)
};

const routeGET = (router, path, handler) => {
    router.route(path)
    .post(methodNotAllowed)
    .get(handler)
    .put(methodNotAllowed)
    .delete(methodNotAllowed)
    .patch(methodNotAllowed)
    .options(methodNotAllowed)
    .head(methodNotAllowed)
};

const routePUT = (router, path, handler) => {
    router.route(path)
    .post(methodNotAllowed)
    .get(methodNotAllowed)
    .put(handler)
    .delete(methodNotAllowed)
    .patch(methodNotAllowed)
    .options(methodNotAllowed)
    .head(methodNotAllowed)
};

const routeDELETE = (router, path, handler) => {
    router.route(path)
    .post(methodNotAllowed)
    .get(methodNotAllowed)
    .put(methodNotAllowed)
    .delete(handler)
    .patch(methodNotAllowed)
    .options(methodNotAllowed)
    .head(methodNotAllowed)
};

const routePATCH = (router, path, handler) => {
    router.route(path)
    .post(methodNotAllowed)
    .get(methodNotAllowed)
    .put(methodNotAllowed)
    .delete(methodNotAllowed)
    .patch(handler)
    .options(methodNotAllowed)
    .head(methodNotAllowed)
};

const routeOPTIONS = (router, path, handler) => {
    router.route(path)
    .post(methodNotAllowed)
    .get(methodNotAllowed)
    .put(methodNotAllowed)
    .delete(methodNotAllowed)
    .patch(methodNotAllowed)
    .options(handler)
    .head(methodNotAllowed)
};

const routeHEAD = (router, path, handler) => {
    router.route(path)
    .post(methodNotAllowed)
    .get(methodNotAllowed)
    .put(methodNotAllowed)
    .delete(methodNotAllowed)
    .patch(methodNotAllowed)
    .options(methodNotAllowed)
    .head(handler)
};

const methodNotAllowed = (req, res) => {
    let _resp_json = {
        result: "ok",
        reason: {
            content: "",
            body: "",
        },
        req_body: {},
        req_param: {}
    }
    _resp_json.result = "fail";
    _resp_json.reason.content = 'Method Not Allowed';
    res.status(405).json(_resp_json);
}

const ROUTER = {
    POST: routePOST,
    GET: routeGET,
    PUT: routePUT,
    DELETE: routeDELETE,
    PATCH: routePATCH,
    OPTIONS: routeOPTIONS,
    HEAD: routeHEAD,
    NOTALLOWED:methodNotAllowed
}

module.exports = { ROUTER };
