import { type UserMood } from 'src/types/userMood';

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

import { computeExpiresAt } from './dates';

export const moodFormToRequest = (values: MoodFormValues): UserMood => {
  if (!values.duration) {
    throw new Error('Mood duration is required');
  }
  const expiresAt = computeExpiresAt(
    values.duration,
    values.customDate,
    values.customTime,
  );
  if (!expiresAt) {
    throw new Error('Could not compute mood expiration');
  }
  return {
    emoji: values.emoji,
    description: values.description.trim(),
    duration: values.duration,
    expiresAt,
  };
};
