// Voice SMS helpers shared between client and server. A voice message is
// typed text that Africa's Talking reads aloud when the recipient answers.

export const VOICE_CREDITS_PER_RECIPIENT = 5
export const MAX_VOICE_RECIPIENTS = 1_000
// About 30 seconds of speech at a normal reading pace.
export const MAX_VOICE_CHARS = 450

export const VOICES = [
  { value: 'woman', label: 'Female', description: 'English, female voice' },
  { value: 'man', label: 'Male', description: 'English, male voice' },
] as const

export type Voice = (typeof VOICES)[number]['value']

export function voiceLabel(voice: string | null | undefined) {
  return VOICES.find((v) => v.value === voice)?.label ?? 'Female'
}

// Roughly 2.6 words per second, rounded up to whole seconds.
export function estimateSpeechSeconds(message: string) {
  const words = message.trim().split(/\s+/).filter(Boolean).length
  return words === 0 ? 0 : Math.max(2, Math.ceil(words / 2.6))
}

// The Africa's Talking settings an admin can enter on /admin/settings.
export const VOICE_FIELDS = [
  { key: 'username', env: 'AFRICASTALKING_USERNAME', label: 'Username', secret: false, hint: 'Your Africa\'s Talking app username. Use "sandbox" to test with the simulator.' },
  { key: 'apiKey', env: 'AFRICASTALKING_API_KEY', label: 'API key', secret: true, hint: 'Generated under Settings → API Key in the same app.' },
  { key: 'phoneNumber', env: 'AFRICASTALKING_VOICE_NUMBER', label: 'Voice phone number', secret: false, hint: 'The Africa\'s Talking voice number calls come from, in international format, e.g. +233302000000.' },
] as const

export type VoiceFieldKey = (typeof VOICE_FIELDS)[number]['key']
