'use server';
/**
 * @fileOverview Generates trail recommendations based on a user-provided description of desired trail conditions.
 *
 * - generateTrailSuggestionsFromDescription - A function that takes a trail description and returns trail recommendations.
 * - GenerateTrailSuggestionsFromDescriptionInput - The input type for the generateTrailSuggestionsFromDescription function.
 * - GenerateTrailSuggestionsFromDescriptionOutput - The return type for the generateTrailSuggestionsFromDescription function.
 */

import {ai} from '@/ai/genkit';
import {z} from 'genkit';

const GenerateTrailSuggestionsFromDescriptionInputSchema = z.object({
  trailDescription: z
    .string()
    .describe(
      'A description of the desired trail conditions, including difficulty, terrain, and scenery.'
    ),
});
export type GenerateTrailSuggestionsFromDescriptionInput = z.infer<
  typeof GenerateTrailSuggestionsFromDescriptionInputSchema
>;

const GenerateTrailSuggestionsFromDescriptionOutputSchema = z.object({
  trailRecommendations: z
    .string()
    .describe('A list of trail recommendations that match the provided description.'),
});
export type GenerateTrailSuggestionsFromDescriptionOutput = z.infer<
  typeof GenerateTrailSuggestionsFromDescriptionOutputSchema
>;

export async function generateTrailSuggestionsFromDescription(
  input: GenerateTrailSuggestionsFromDescriptionInput
): Promise<GenerateTrailSuggestionsFromDescriptionOutput> {
  return generateTrailSuggestionsFromDescriptionFlow(input);
}

const prompt = ai.definePrompt({
  name: 'generateTrailSuggestionsFromDescriptionPrompt',
  input: {schema: GenerateTrailSuggestionsFromDescriptionInputSchema},
  output: {schema: GenerateTrailSuggestionsFromDescriptionOutputSchema},
  prompt: `You are an expert trail recommendation system. A user will provide a description of their desired trail conditions, and you will provide a list of trail recommendations that match their preferences.\n\nDesired trail conditions: {{{trailDescription}}}\n\nTrail recommendations:`,
});

const generateTrailSuggestionsFromDescriptionFlow = ai.defineFlow(
  {
    name: 'generateTrailSuggestionsFromDescriptionFlow',
    inputSchema: GenerateTrailSuggestionsFromDescriptionInputSchema,
    outputSchema: GenerateTrailSuggestionsFromDescriptionOutputSchema,
  },
  async input => {
    const {output} = await prompt(input);
    return output!;
  }
);
