import type { SerenityScore } from '$types';

export type SerenityEmoji = '💚' | '🟡' | '🔴';

/**
 * Calculates the serenity score from its components
 * Score = (Notes × 0.4) + (Absences × 0.3) + (Devoirs × 0.3)
 */
export function calculateSerenityScore(components: {
	notes: number;
	absences: number;
	devoirs: number;
}): number {
	const score = components.notes * 0.4 + components.absences * 0.3 + components.devoirs * 0.3;
	return Math.round(score);
}

/**
 * Gets the appropriate emoji for a serenity score
 * 💚 Green: Score >= 70
 * 🟡 Orange: Score 40-69
 * 🔴 Red: Score < 40
 */
export function getSerenityEmoji(score: number): SerenityEmoji {
	if (score >= 70) return '💚';
	if (score >= 40) return '🟡';
	return '🔴';
}

/**
 * Gets a human-readable label for the serenity score
 */
export function getSerenityLabel(score: number): string {
	if (score >= 70) return 'Excellent';
	if (score >= 40) return 'A surveiller';
	return 'Attention requise';
}

/**
 * Validates that a serenity score value is within valid bounds
 */
export function isValidScore(score: number): boolean {
	return score >= 0 && score <= 100;
}

/**
 * Gets trend icon for score comparison
 */
export function getTrendIcon(trend: SerenityScore['trend']): string {
	switch (trend) {
		case 'up':
			return '↑';
		case 'down':
			return '↓';
		case 'stable':
		default:
			return '→';
	}
}
