export default (callApi) => ({
	getSettings(token) {
		return callApi('GET', '/v1/settings/allow-list', { token })
			.then((res) => ({
				autoAcceptFriend: !res.ACTIVE_EMAIL_FILTER,
				defaultPlaylistId: res.EMAIL_DEFAULT_SLIDESHOW_ID,
			}))
			.catch((res) => Promise.reject(res.message));
	},

	setSettings(token, settings) {
		const data = {};
		// console.log('token ', token);
		// console.log('payload ', JSON.stringify(settings));
		Object.keys(settings).forEach((k) => {
			if (k === 'autoAcceptFriend') data.ACTIVE_EMAIL_FILTER = !settings.autoAcceptFriend;
			if (k === 'defaultPlaylistId') data.EMAIL_DEFAULT_SLIDESHOW_ID = settings.defaultPlaylistId;
		});
		if (Object.keys(data).length === 0) {
			return Promise.resolve(true);
		}
		return callApi('PUT', '/v1/settings/allow-list', { token, data })
			.then((res) => res.success)
			.catch((res) => Promise.reject(res.message));
	},

	// changePassword(token, username, password, newPassword) {
	// 	return callApi('POST', '/v1/auth/change-password', {
	// 		token,
	// 		data: { username, password, newPassword },
	// 	})
	// 		.then((res) => res)
	// 		.catch((res) => Promise.reject(res.message));
	// },

	changeUserSettings(token, payload) {
		return callApi('PUT', '/v1/auth/settings', {
			token, ...payload,
		})
			.then((res) => res)
			.catch((res) => Promise.reject(res.message));
	},
});
