import { Pool, Client } from 'pg';
import DBCONFIG from '../database-info.json';

export function usersController(req, res) {
    console.log("you hit the helper function.");
    res.send("you hit the helper function!");
};

// Query user table for user info for profile page
export function users_profile_get(req, res) {
	const userKey = req.params.id;

	const sqlQuery = 'SELECT ukey, ufname, ulname, udisplay, uemail, uphone, upicture, \
										uposition, urole, upassword, ulastlogin, ualtuser, uavailable \
										FROM users WHERE ukey = ' + userKey;

	req.app.locals.pool.query(sqlQuery, (error, result) => {
		if (error) {
			res.status(400).json({
				"Error":error.stack
			})
		} else {
			res.send(result.rows[0]);
		}
	});
	
};

// Update user table with new user info from profile page
export function users_profile_post(req, res) {
	const sqlQuery = {
			                text: 'UPDATE users SET udisplay = $1, uphone = $2 \
			                       WHERE ukey = $3',
			                values: [req.body.udisplay, req.body.uphone, req.body.ukey]
            			 }

	req.app.locals.pool.query(sqlQuery, (error, result) => {
		if (error) {
			res.status(400).json({
				"Error":error.stack
			})
		} else {
			console.log("User Profile Updated! " + result.rows[0]);
		}
	})
};

export function users_inbox_get(req, res) {
	res.send('NOT IMPLEMENTED');
};

export function users_inbox_recent_get(req, res) {
	res.send('NOT IMPLEMENTED');
};

export function users_inbox_relevant_get(req, res) {
	res.send('NOT IMPLEMENTED');
};

export function users_inbox_priority_get(req, res) {
	res.send('NOT IMPLEMENTED');
};