use rocket::serde::{json::Json};
use rocket::response::status;
use rocket::{get, post};

use crate::models::sensors::SensorData;
use crate::models::sensors::get_sensor_data;

use crate::repository::remote::redis;

// get data json obj
    // database.getSensorData()
    // send 200 http response with json obj
// 500
// create data json obj
    // database.create(obj)
    // send 200 http response
// 500

#[post("/sensors/data", format="json", data="<json>")]
pub async fn create(json: Json<SensorData>) -> status::Accepted<Json<SensorData>> {
    let received_data = json.into_inner();

    let data = get_sensor_data();
    status::Accepted(Json(data))

    // saved_data = database.create(data);
    // status::Accepted(Json(saved_data))
}

#[get("/sensors/data")]
pub async fn get() ->  status::Accepted<Json<SensorData>> {
    // get all data from DB
    let data = get_sensor_data();
    
    status::Accepted(Json(data))
}

// #[get("/sensors/data/<id>")]
// pub async fn get_by_id(id: u32) -> status::Accepted<Json<SensorData>> {
//     // Vulnirability: danger if ID in sql requsets
//     // http://127.0.0.1:8000/api/v1/sensors/data/?query=SELECT%20id%20FROM%20sensors
    
//     // get data from DB
//     let data = get_sensor_data();
    
//     status::Accepted(Json(data))
// }

