import { z } from 'zod';

/**
 * Schema for detect_quick_wins tool
 * Finds pages ranking in positions 4-20 with high impressions but low CTR
 */
export const QuickWinsSchema = z.object({
  siteUrl: z.string().url().describe('The Google Search Console property URL (e.g., https://example.com)'),
  startDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe('Start date in YYYY-MM-DD format'),
  endDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe('End date in YYYY-MM-DD format'),
  days: z.number().int().positive().optional().describe('Relative date range (e.g., 90 for last 90 days). Overrides startDate/endDate if provided.'),
  positionRangeMin: z.number().min(1).max(100).default(4).describe('Minimum position to consider (default: 4)'),
  positionRangeMax: z.number().min(1).max(100).default(20).describe('Maximum position to consider (default: 20)'),
  minImpressions: z.number().int().min(0).default(100).describe('Minimum impressions to qualify (default: 100)'),
  maxCtr: z.number().min(0).max(100).default(5).describe('Maximum CTR percentage to qualify (default: 5)'),
  limit: z.number().int().min(1).max(1000).default(50).describe('Maximum number of results to return (default: 50)')
});

/**
 * Schema for keyword_cannibalization tool
 * Finds queries that rank multiple pages, diluting authority
 */
export const KeywordCannibalizationSchema = z.object({
  siteUrl: z.string().url().describe('The Google Search Console property URL'),
  startDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe('Start date in YYYY-MM-DD format'),
  endDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe('End date in YYYY-MM-DD format'),
  days: z.number().int().positive().optional().describe('Relative date range (e.g., 90 for last 90 days)'),
  minImpressions: z.number().int().min(0).default(50).describe('Minimum impressions per query to analyze (default: 50)'),
  queryFilter: z.string().optional().describe('Optional regex pattern to filter queries (e.g., ".*buy.*")'),
  limit: z.number().int().min(1).max(1000).default(100).describe('Maximum number of cannibalized queries to return (default: 100)')
});

/**
 * Schema for content_decay_detection tool
 * Identifies pages that have lost significant traffic over time
 */
export const ContentDecaySchema = z.object({
  siteUrl: z.string().url().describe('The Google Search Console property URL'),
  lookbackDays: z.number().int().min(30).max(365).default(90).describe('How far back to check for peak performance (default: 90)'),
  comparisonDays: z.number().int().min(7).max(90).default(30).describe('Recent period to compare against (default: 30)'),
  minClicksInPeak: z.number().int().min(1).default(10).describe('Minimum clicks in peak period to qualify (default: 10)'),
  decayThreshold: z.number().min(0).max(1).default(0.3).describe('Minimum decay percentage to flag (default: 0.3 = 30%)'),
  limit: z.number().int().min(1).max(1000).default(50).describe('Maximum number of decaying pages to return (default: 50)')
});

/**
 * Schema for query_clustering tool
 * Groups similar queries to identify content gaps and opportunities
 */
export const QueryClusteringSchema = z.object({
  siteUrl: z.string().url().describe('The Google Search Console property URL'),
  startDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe('Start date in YYYY-MM-DD format'),
  endDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe('End date in YYYY-MM-DD format'),
  days: z.number().int().positive().optional().describe('Relative date range (e.g., 90 for last 90 days)'),
  minImpressions: z.number().int().min(0).default(10).describe('Minimum impressions per query to include (default: 10)'),
  similarityThreshold: z.number().min(0).max(1).default(0.6).describe('Jaccard similarity threshold for clustering (default: 0.6)'),
  limit: z.number().int().min(1).max(1000).default(100).describe('Maximum number of clusters to return (default: 100)')
});
