use indexed_valued_enums_derive::{EnumIndexed, EnumValued, EnumValuedFromCSV, DefineEnumValuedFromCSV};

#[derive(EnumValuedFromCSV, PartialEq, Debug)]
#[EnumValuedFromCSV(pub in_crate "tests/test_csv/planets_info.csv")]
#[EnumIndexed]
enum Planets{
    Earth, Mercury
}

#[EnumIndexed]
enum PlanetsWithSeparatedDefinition{
    Earth, Mercury
}

DefineEnumValuedFromCSV! { pub(self) in_crate "tests/test_csv/planets_info.csv" for PlanetsWithSeparatedDefinition }

#[cfg(feature = "parameter_types")]
#[derive(EnumValuedFromCSV)]
#[EnumValuedFromCSV(pub in_crate "tests/test_csv/planets_info.csv")]
#[EnumIndexed(Consts(T: u8, O:u8))]
enum PlanetsWithTypes<'lf, 'ot, const N: usize, const A: bool, T, O>
where
    T:Into<u8>,
    T:Into<u8>,
    O:Into<u8>,
{
    Earth, Mercury(&'lf &'ot(O,T))
}



#[test]
pub fn main() {
    // Iterate over every variant.
    Planets::VARIANTS.iter().for_each(|planet|{
        let name = planet.variant_name();
        let gravity = planet.gravity();
        println!("The planet {name} has a gravity of {gravity}");
    });

    // Get a variant from its name.
    let earth = Planets::from_variant_name("Earth").unwrap();
    let name = earth.variant_name();
    let gravity = earth.gravity();
    println!("The planet {name} is our home, and it has a gravity of {gravity}");

    // Get a variant's index.
    let earth_index_in_enum = Planets::Earth.variant_index();
    println!("Planet Earth has and index of {earth_index_in_enum}");

    // Get a variant's from its index.
    // In this case, the planet earth is the variant with index 2.
    let earth = Planets::from_variant_index(earth_index_in_enum).unwrap();
    let earth_from_raw_index = Planets::from_variant_index(0).unwrap();

    assert_eq!(earth, Planets::Earth);
    assert_eq!(earth_from_raw_index, Planets::Earth);

    // Get a planet out of its gravity.
    let planet_with_9_8_gravity = Planets::from_gravity(&9.8).unwrap();

    println!("The planet with 9.8 gravity is {}", planet_with_9_8_gravity.variant_name());
}
