import { describe, it, expect } from 'vitest';
import { CreateMealPlanSchema } from './meal-plan.schemas.js';
import { MealType, MealPlanStatus } from '../enums/meal-plan.enums.js';

describe('MealPlan Schemas', () => {
  const validMeal = {
    id: '550e8400-e29b-41d4-a716-446655440000',
    type: MealType.DINNER,
    recipeName: 'Chicken Salad',
    servings: 2,
    perServingNutrition: { calories: 300, protein: 30, carbs: 10, fat: 15 },
  };

  const validDay = {
    date: '2026-05-18',
    meals: [validMeal],
    dailyNutritionTotal: { calories: 600, protein: 60, carbs: 20, fat: 30 },
  };

  const validPlan = {
    weekStartDate: '2026-05-18',
    days: Array(7).fill(validDay),
    status: MealPlanStatus.DRAFT,
  };

  it('should validate a valid meal plan', () => {
    const result = CreateMealPlanSchema.safeParse(validPlan);
    expect(result.success).toBe(true);
  });

  it('should reject a plan with missing days', () => {
    const invalidPlan = { ...validPlan, days: validPlan.days.slice(0, 6) };
    const result = CreateMealPlanSchema.safeParse(invalidPlan);
    expect(result.success).toBe(false);
  });

  it('should reject invalid date format', () => {
    const invalidPlan = { ...validPlan, weekStartDate: '18-05-2026' };
    const result = CreateMealPlanSchema.safeParse(invalidPlan);
    expect(result.success).toBe(false);
  });
});
