import { z } from 'zod';

export const CodeQualityIssueSchema = z.object({
  id: z.string(),
  type: z.enum(['error', 'warning', 'info']),
  category: z.enum(['typescript', 'eslint', 'build', 'test', 'format']),
  file: z.string(),
  line: z.number().optional(),
  column: z.number().optional(),
  message: z.string(),
  rule: z.string().optional(),
});

export type CodeQualityIssue = z.infer<typeof CodeQualityIssueSchema>;

export const CodeQualityReportSchema = z.object({
  id: z.string(),
  projectId: z.string(),
  projectName: z.string(),
  projectPath: z.string(),
  timestamp: z.string(),
  summary: z.object({
    totalIssues: z.number(),
    errors: z.number(),
    warnings: z.number(),
    infos: z.number(),
  }),
  categories: z.object({
    typescript: z.object({
      errors: z.number(),
      warnings: z.number(),
      duration: z.number(),
    }),
    eslint: z.object({
      errors: z.number(),
      warnings: z.number(),
      duration: z.number(),
    }),
    build: z.object({
      success: z.boolean(),
      duration: z.number(),
      errors: z.number(),
    }),
    test: z.object({
      success: z.boolean(),
      passed: z.number(),
      failed: z.number(),
      duration: z.number(),
    }),
  }),
  issues: z.array(CodeQualityIssueSchema),
});

export type CodeQualityReport = z.infer<typeof CodeQualityReportSchema>;

export const CodeQualityCheckParamsSchema = z.object({
  projectId: z.string(),
  projectPath: z.string(),
  checks: z.array(z.enum(['typescript', 'eslint', 'build', 'test'])).default(['typescript', 'eslint', 'build', 'test']),
});

export type CodeQualityCheckParams = z.infer<typeof CodeQualityCheckParamsSchema>;
