import type { TradeSetup } from './types';

export type RecommendationAction = NonNullable<TradeSetup['recommended_action']>;

export const RECOMMENDATION_ACTION_LABELS: Record<RecommendationAction, string> = {
  LONG_HIGH: 'LONG (High Confidence)',
  LONG_MODERATE: 'LONG (Moderate Confidence)',
  SHORT_HIGH: 'SHORT (High Confidence)',
  SHORT_MODERATE: 'SHORT (Moderate Confidence)',
  NEUTRAL: 'NEUTRAL (No Clear Setup)',
};

export const RECOMMENDATION_ACTION_GLOSSARY: Array<{ action: RecommendationAction; description: string }> = [
  {
    action: 'LONG_HIGH',
    description: 'Ticker bias favors LONG strongly. LONG confidence is above the high threshold and clearly above SHORT.',
  },
  {
    action: 'LONG_MODERATE',
    description: 'Ticker bias favors LONG, but with moderate conviction.',
  },
  {
    action: 'SHORT_HIGH',
    description: 'Ticker bias favors SHORT strongly. SHORT confidence is above the high threshold and clearly above LONG.',
  },
  {
    action: 'SHORT_MODERATE',
    description: 'Ticker bias favors SHORT, but with moderate conviction.',
  },
  {
    action: 'NEUTRAL',
    description: 'No actionable setup — either signals are mixed, or the favored direction has no tradeable setup (e.g. price extended with no target). See the reasoning for which.',
  },
];

export function recommendationActionLabel(action: TradeSetup['recommended_action']): string {
  if (!action) return RECOMMENDATION_ACTION_LABELS.NEUTRAL;
  return RECOMMENDATION_ACTION_LABELS[action] ?? RECOMMENDATION_ACTION_LABELS.NEUTRAL;
}

export function recommendationActionDirection(action: TradeSetup['recommended_action']): 'long' | 'short' | 'neutral' {
  if (!action || action === 'NEUTRAL') return 'neutral';
  if (action.startsWith('LONG')) return 'long';
  if (action.startsWith('SHORT')) return 'short';
  return 'neutral';
}
