/**
 * Name Service
 * Generate random first and last names for characters
 * Ported from Python character/character_manager.py
 */

import { Sex } from '../../models/Person.js';

// Common male first names
const MALE_FIRST_NAMES = [
  'Liam', 'Noah', 'Oliver', 'Elijah', 'James', 'William', 'Benjamin', 'Lucas',
  'Henry', 'Alexander', 'Mason', 'Michael', 'Ethan', 'Daniel', 'Jacob',
  'Logan', 'Jackson', 'Levi', 'Sebastian', 'Mateo', 'Jack', 'Owen', 'Theodore',
  'Aiden', 'Samuel', 'Joseph', 'John', 'David', 'Wyatt', 'Matthew',
  'Luke', 'Asher', 'Carter', 'Julian', 'Grayson', 'Leo', 'Jayden', 'Gabriel',
  'Isaac', 'Lincoln', 'Anthony', 'Hudson', 'Dylan', 'Ezra', 'Thomas',
  'Charles', 'Christopher', 'Jaxon', 'Maverick', 'Josiah', 'Isaiah', 'Andrew',
  'Ryan', 'Nathan', 'Caleb', 'Hunter', 'Adrian', 'Connor', 'Joshua', 'Nolan',
];

// Common female first names
const FEMALE_FIRST_NAMES = [
  'Emma', 'Olivia', 'Ava', 'Isabella', 'Sophia', 'Mia', 'Charlotte', 'Amelia',
  'Harper', 'Evelyn', 'Abigail', 'Emily', 'Elizabeth', 'Mila', 'Ella',
  'Avery', 'Sofia', 'Camila', 'Aria', 'Scarlett', 'Victoria', 'Madison',
  'Luna', 'Grace', 'Chloe', 'Penelope', 'Layla', 'Riley', 'Zoey', 'Nora',
  'Lily', 'Eleanor', 'Hannah', 'Lillian', 'Addison', 'Aubrey', 'Ellie',
  'Stella', 'Natalie', 'Zoe', 'Leah', 'Hazel', 'Violet', 'Aurora', 'Savannah',
  'Audrey', 'Brooklyn', 'Bella', 'Claire', 'Skylar', 'Lucy', 'Paisley',
  'Everly', 'Anna', 'Caroline', 'Nova', 'Genesis', 'Emilia', 'Kennedy', 'Sadie',
];

// Common last names
const LAST_NAMES = [
  'Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis',
  'Rodriguez', 'Martinez', 'Hernandez', 'Lopez', 'Gonzalez', 'Wilson', 'Anderson',
  'Thomas', 'Taylor', 'Moore', 'Jackson', 'Martin', 'Lee', 'Perez', 'Thompson',
  'White', 'Harris', 'Sanchez', 'Clark', 'Ramirez', 'Lewis', 'Robinson',
  'Walker', 'Young', 'Allen', 'King', 'Wright', 'Scott', 'Torres', 'Nguyen',
  'Hill', 'Flores', 'Green', 'Adams', 'Nelson', 'Baker', 'Hall', 'Rivera',
  'Campbell', 'Mitchell', 'Carter', 'Roberts', 'Gomez', 'Phillips', 'Evans',
  'Turner', 'Diaz', 'Parker', 'Cruz', 'Edwards', 'Collins', 'Reyes', 'Stewart',
];

/**
 * Get a random element from an array
 */
function randomChoice<T>(arr: T[]): T {
  return arr[Math.floor(Math.random() * arr.length)];
}

/**
 * Get a random last name
 */
export function getLastname(): string {
  return randomChoice(LAST_NAMES);
}

/**
 * Get a random first name based on gender
 */
export function getFirstname(gender: Sex): string {
  if (gender === 'Female') {
    return randomChoice(FEMALE_FIRST_NAMES);
  }
  return randomChoice(MALE_FIRST_NAMES);
}

/**
 * Get the opposite sex
 */
export function getOppositeSex(sex: Sex): Sex {
  return sex === 'Male' ? 'Female' : 'Male';
}

/**
 * Get a random sex
 */
export function getRandomSex(): Sex {
  return Math.random() < 0.5 ? 'Male' : 'Female';
}
