use dittolive_ditto::store::collection::document_id::DocumentId;
use rand::seq::SliceRandom;
use serde::{Deserialize, Serialize};

const COLORS: [&str; 15] = [
    "Red🔴",
    "Blue🔵",
    "Green🟢",
    "Yellow🟡",
    "Pink🦩",
    "Brown🟤",
    "Purple🟣",
    "White🤍",
    "Black⚫",
    "Rainbow🌈",
    "Golden🪙",
    "Silver🥈",
    "Bronze🥉",
    "Invisible👻",
    "Batmobile🦇",
];
const BRANDS: [&str; 14] = [
    "Mercedes",
    "Citroën",
    "Ford",
    "Ferrari",
    "Renault",
    "Bugatti",
    "BMW",
    "Hyundai",
    "Toyota",
    "Volkswagen",
    "Fiat",
    "Škoda",
    "Lada",
    "Mitsubishi",
];

#[derive(Default, Debug, Serialize, Deserialize)]
pub struct Car {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub _id: Option<DocumentId>,
    color: String,
    brand: String,
    kilometers: u8,
}

impl Car {
    pub fn generate() -> Self {
        let color = COLORS.choose(&mut rand::thread_rng()).unwrap().to_string();
        let brand = BRANDS.choose(&mut rand::thread_rng()).unwrap().to_string();
        let kilometers = rand::random::<u8>();
        Car {
            _id: None,
            color,
            brand,
            kilometers,
        }
    }

    pub fn display(&self) -> String {
        format!(
            "|{:>14}|{:>10}|{:>5}|",
            self.brand, self.color, self.kilometers,
        )
    }

    pub fn header() -> String {
        format!("  |{:>14}|{:>11}|{:>5}|", "BRAND", "COLOR", "KMS",)
    }
}
