use hyper::{Response, Body, StatusCode};
use mysql_async::Pool;
use serde_json::json;

use db::member::STATUS_ONLINE;
use db::common::FromDB;

use crate::http::set_json_body;

pub async fn get_online_members(p: &Pool, response: &mut Response<Body>) {
    // TODO: at some point we should provide a way of not querying literally every user in
    // existance
    // TODO: loggin at some point or something idklol
    return match db::channels::Channel::filter(p, STATUS_ONLINE).await {
        db::Response::Set(users) => {
            set_json_body(response, json!(users));
        },
        db::Response::Other(_msg) => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
        _ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
    }
}
