use std::io::Read;
use std::fs::File;
use std::path::PathBuf;
use std::env::home_dir;

use serde_json;

#[derive(Debug, Serialize, Deserialize)]
pub struct XyPair {
    pub x: u32,
    pub y: u32
}

impl XyPair {
    #[allow(dead_code)]
    pub fn new (x: u32, y: u32) -> Self {
        XyPair { x, y }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Screen {
    pub resolution: XyPair,
    pub offset: XyPair
}

impl Screen {
    #[allow(dead_code)]
    pub fn new(x: u32, y: u32, offset_x: u32, offset_y: u32) -> Self {
        Screen {
            resolution: XyPair::new(x, y),
            offset: XyPair::new(offset_x, offset_y)
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
    pub resolution: XyPair,
    pub screens: Vec<Screen>
}

impl Config {
    #[allow(dead_code)]
    pub fn new(x: u32, y: u32, screens: Vec<Screen>) -> Self 

}

fn config_path() -> PathBuf {
    home_dir()
        .expect("Failed to locate home directory.")
        .join(".config")
        .join("scrotrim")
        .join("config.json")
}

pub fn read_config() -> Config {
    let path = config_path();
    let mut body = String::new();
    let mut file = File::open(&path).expect("Failed to open config.");
    file.read_to_string(&mut body).expect("Failed to read config.");
    serde_json::from_str(&body).expect("Failed to parse config.")
}

{
        Config {
            resolution: XyPair::new(x, y),
            screens
        }
    }