use crate::Response;
use std::collections::HashMap;

pub struct JsonResponse;

impl JsonResponse {
    pub fn new(json: serde_json::Value, code: u8) -> Response {
        let mut headers = HashMap::new();
        headers.insert("Content-Type".to_string(), "application/json".to_string());

        Response {
            code,
            headers,
            body: serde_json::to_vec(&json).unwrap(),
        }
    }

    pub fn new_ok(json: serde_json::Value) -> Response {
        Self::new(json, 200)
    }
}
