const siteMap = {
	'ws1': 1,
	'worldshine1': 1,
	'ws2': 2,
	'worldshine2': 2,
	'ws3': 3,
	'worldshine3': 3,
	'worldshine4': 4,
	'ws4': 4,
	'worldshine.mayo.llc': 1
};

const findSiteNumber = (req) => {
	const hostname = req.hostname;
	let site = 1;
	for (const key of Object.keys(siteMap)) {
		if (hostname.includes(key)) {
			site = siteMap[key];
			break;
		}
	}
	return site;
}

const splitSiteGet = (req, queryParams) => {
	const site = findSiteNumber(req);
	const newQueryParams = { ...queryParams, site: site };
	return newQueryParams;
}

const splitSitePost = (req, postBody) => {
	const site = findSiteNumber(req);
	const newPostBody = { ...postBody, site: site };
	return newPostBody;
}

const splitSite = {
	findSiteNumber,
	splitSiteGet,
	splitSitePost
} 

module.exports = splitSite; 