// SPDX-FileCopyrightText: 2023 CELESTIFYX Team
// SPDX-License-Identifier: GPL-3.0-or-later

use std::str::FromStr;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InfoPosition {
    Top    = 0,
    Right  = 1,
    Left   = 2,
    Bottom = 3
}

impl FromStr for InfoPosition {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "top"    => Ok(InfoPosition::Top),
            "right"  => Ok(InfoPosition::Right),
            "left"   => Ok(InfoPosition::Left),
            "bottom" => Ok(InfoPosition::Bottom),

            _        => Err(s.to_string())
        }
    }
}

#[derive(Debug, Clone)]
pub struct InfoConfig {
    pub lines: Vec<String>,
    pub position: InfoPosition,
    pub margin: usize
}

impl InfoConfig {
    pub fn new(lines: Vec<String>) -> Self {
        Self {
            lines,
            position: InfoPosition::Right,
            margin: 4
        }
    }

    pub fn with_position(mut self, position: InfoPosition) -> Self {
        self.position = position;
        self
    }

    pub fn with_margin(mut self, margin: usize) -> Self {
        self.margin = margin;
        self
    }
}
