'use server';

/**
 * @fileOverview Summarizes trail reports for quick understanding.
 *
 * - summarizeTrailReports - A function that summarizes trail reports.
 * - SummarizeTrailReportsInput - The input type for the summarizeTrailReports function.
 * - SummarizeTrailReportsOutput - The return type for the summarizeTrailReports function.
 */

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

const SummarizeTrailReportsInputSchema = z.object({
  trailReport: z.string().describe('The trail report to summarize.'),
});
export type SummarizeTrailReportsInput = z.infer<typeof SummarizeTrailReportsInputSchema>;

const SummarizeTrailReportsOutputSchema = z.object({
  summary: z.string().describe('A concise summary of the trail report.'),
});
export type SummarizeTrailReportsOutput = z.infer<typeof SummarizeTrailReportsOutputSchema>;

export async function summarizeTrailReports(input: SummarizeTrailReportsInput): Promise<SummarizeTrailReportsOutput> {
  return summarizeTrailReportsFlow(input);
}

const summarizeTrailReportsPrompt = ai.definePrompt({
  name: 'summarizeTrailReportsPrompt',
  input: {schema: SummarizeTrailReportsInputSchema},
  output: {schema: SummarizeTrailReportsOutputSchema},
  prompt: `Summarize the following trail report in a concise and informative way:\n\n{{{trailReport}}}`,
});

const summarizeTrailReportsFlow = ai.defineFlow(
  {
    name: 'summarizeTrailReportsFlow',
    inputSchema: SummarizeTrailReportsInputSchema,
    outputSchema: SummarizeTrailReportsOutputSchema,
  },
  async input => {
    const {output} = await summarizeTrailReportsPrompt(input);
    return output!;
  }
);
