//
// lexis: Generates Pink Floyd song titles from numeric values
// src/lib.rs: Common utility functions
//
// Copyright (c) 2024, 2026 Ali Polatel <alip@chesswob.org>
//
// SPDX-License-Identifier: GPL-3.0

mod list;

use crate::list::{NAMES, NAMES_LOWER};

/// Trait to convert numeric values to Pink Floyd song titles.
pub trait ToName {
    /// Return Pink Floyd song title verbatim.
    fn to_name(self) -> &'static str;
    /// Return Pink Floyd song title lowercased.
    fn to_name_lower(self) -> &'static str;
}

macro_rules! impl_to_name {
    ($($t:ty),*) => {
        $(impl ToName for $t {
            fn to_name(self) -> &'static str {
                NAMES[name_index(self.into())]
            }
            fn to_name_lower(self) -> &'static str {
                NAMES_LOWER[name_index(self.into())]
            }
        })*
    };
}

impl_to_name!(u8, u16, u32, u64);

fn name_index(number: u64) -> usize {
    (number % NAMES.len() as u64) as usize
}
