/**
 * Admin Coaching System - Data Models and Types
 */

export type CoachingArea = 'approval_speed' | 'accuracy' | 'consistency' | 'communication' | 'decision_quality' | 'workload_management';

export type RecommendationPriority = 'critical' | 'high' | 'medium' | 'low';

export type TrainingResourceType = 'video' | 'article' | 'guide' | 'checklist' | 'webinar' | 'case_study';

export interface CoachingRecommendation {
  id: string;
  adminId: number;
  area: CoachingArea;
  title: string;
  description: string;
  priority: RecommendationPriority;
  targetMetric: string;
  currentValue: number;
  targetValue: number;
  estimatedTimeToImprove: number; // in days
  actionItems: string[];
  relatedResources: string[];
  createdAt: Date;
  targetDate: Date;
  status: 'active' | 'completed' | 'dismissed';
}

export interface TrainingResource {
  id: string;
  title: string;
  description: string;
  type: TrainingResourceType;
  category: CoachingArea;
  duration: number; // in minutes
  difficulty: 'beginner' | 'intermediate' | 'advanced';
  url: string;
  tags: string[];
  completionRate: number; // 0-100
  rating: number; // 0-5
}

export interface AdminCoachingProfile {
  adminId: number;
  adminName: string;
  role: string;
  joinDate: Date;
  performanceScore: number; // 0-100
  strengths: CoachingArea[];
  improvementAreas: CoachingArea[];
  recommendations: CoachingRecommendation[];
  completedTrainings: string[]; // training IDs
  inProgressTrainings: string[]; // training IDs
  coachingHistory: CoachingHistoryEntry[];
}

export interface CoachingHistoryEntry {
  id: string;
  date: Date;
  type: 'recommendation_created' | 'training_completed' | 'metric_improved' | 'milestone_reached' | 'feedback_given';
  title: string;
  description: string;
  impact: number; // -100 to 100
}

export interface CoachingGoal {
  id: string;
  adminId: number;
  area: CoachingArea;
  title: string;
  description: string;
  targetValue: number;
  currentValue: number;
  deadline: Date;
  priority: RecommendationPriority;
  status: 'active' | 'completed' | 'abandoned';
  progress: number; // 0-100
  milestones: GoalMilestone[];
}

export interface GoalMilestone {
  id: string;
  title: string;
  targetValue: number;
  dueDate: Date;
  completed: boolean;
  completedDate?: Date;
}

export interface CoachingInsight {
  id: string;
  adminId: number;
  date: Date;
  type: 'strength' | 'weakness' | 'trend' | 'opportunity' | 'risk';
  title: string;
  description: string;
  confidence: number; // 0-100
  actionable: boolean;
  suggestedAction?: string;
}

export interface AdminCoachingStats {
  totalRecommendations: number;
  activeRecommendations: number;
  completedRecommendations: number;
  recommendationCompletionRate: number;
  totalTrainingsCompleted: number;
  averageTrainingRating: number;
  improvementTrend: number; // -100 to 100
  estimatedPerformanceGain: number; // 0-100
  coachingEngagementScore: number; // 0-100
}

/**
 * Coaching Recommendation Templates
 */
export const COACHING_TEMPLATES: Record<CoachingArea, CoachingRecommendationTemplate[]> = {
  approval_speed: [
    {
      title: 'Accelerate Approval Process',
      description: 'Your approval time is 25% above team average. Let\'s work on streamlining your workflow.',
      actionItems: [
        'Review your current approval checklist - identify non-essential steps',
        'Set daily approval targets (e.g., 50 approvals/day)',
        'Use batch processing for similar items',
        'Implement keyboard shortcuts for common actions',
      ],
      targetMetric: 'Average Approval Time',
      improvementPotential: 30,
      estimatedDays: 14,
    },
    {
      title: 'Optimize Decision Making',
      description: 'Reduce decision time by implementing a decision framework.',
      actionItems: [
        'Create a decision matrix for common scenarios',
        'Pre-define approval criteria',
        'Use templates for standard responses',
        'Delegate routine approvals to junior staff',
      ],
      targetMetric: 'Average Approval Time',
      improvementPotential: 20,
      estimatedDays: 7,
    },
  ],
  accuracy: [
    {
      title: 'Improve Decision Accuracy',
      description: 'Your error rate is higher than expected. Let\'s focus on quality over speed.',
      actionItems: [
        'Implement a double-check process for critical decisions',
        'Review recent errors to identify patterns',
        'Take accuracy-focused training',
        'Reduce daily workload to improve focus',
      ],
      targetMetric: 'Error Rate',
      improvementPotential: 40,
      estimatedDays: 21,
    },
    {
      title: 'Enhance Verification Skills',
      description: 'Strengthen your ability to catch errors before approval.',
      actionItems: [
        'Study common fraud patterns',
        'Practice with case studies',
        'Use verification checklists',
        'Attend fraud detection training',
      ],
      targetMetric: 'Error Rate',
      improvementPotential: 35,
      estimatedDays: 14,
    },
  ],
  consistency: [
    {
      title: 'Build Consistent Performance',
      description: 'Your performance varies significantly day-to-day. Let\'s stabilize it.',
      actionItems: [
        'Establish a daily routine and schedule',
        'Track daily metrics to identify patterns',
        'Address external factors affecting performance',
        'Take consistency-focused training',
      ],
      targetMetric: 'Performance Variance',
      improvementPotential: 25,
      estimatedDays: 30,
    },
  ],
  communication: [
    {
      title: 'Improve Communication Skills',
      description: 'Enhance your ability to communicate decisions and feedback clearly.',
      actionItems: [
        'Take communication skills training',
        'Practice writing clear decision explanations',
        'Use templates for common communications',
        'Get feedback from peers on your communication',
      ],
      targetMetric: 'Communication Score',
      improvementPotential: 30,
      estimatedDays: 21,
    },
  ],
  decision_quality: [
    {
      title: 'Enhance Decision Quality',
      description: 'Improve the quality of your decisions through better analysis.',
      actionItems: [
        'Study decision-making frameworks',
        'Review past decisions for lessons learned',
        'Use data-driven decision tools',
        'Consult with senior team members',
      ],
      targetMetric: 'Decision Quality Score',
      improvementPotential: 35,
      estimatedDays: 28,
    },
  ],
  workload_management: [
    {
      title: 'Manage Workload Effectively',
      description: 'Balance your workload to maintain quality and avoid burnout.',
      actionItems: [
        'Prioritize high-impact tasks',
        'Delegate routine work',
        'Take regular breaks',
        'Use time management tools',
      ],
      targetMetric: 'Workload Balance',
      improvementPotential: 20,
      estimatedDays: 14,
    },
  ],
};

export interface CoachingRecommendationTemplate {
  title: string;
  description: string;
  actionItems: string[];
  targetMetric: string;
  improvementPotential: number;
  estimatedDays: number;
}

/**
 * Training Resources Library
 */
export const TRAINING_RESOURCES: TrainingResource[] = [
  {
    id: 'tr_001',
    title: 'Approval Process Optimization',
    description: 'Learn techniques to streamline your approval workflow and reduce processing time.',
    type: 'video',
    category: 'approval_speed',
    duration: 15,
    difficulty: 'beginner',
    url: 'https://example.com/training/approval-optimization',
    tags: ['workflow', 'efficiency', 'process'],
    completionRate: 0,
    rating: 4.5,
  },
  {
    id: 'tr_002',
    title: 'Fraud Detection Best Practices',
    description: 'Master the techniques for identifying and preventing fraudulent activities.',
    type: 'guide',
    category: 'accuracy',
    duration: 30,
    difficulty: 'intermediate',
    url: 'https://example.com/training/fraud-detection',
    tags: ['security', 'fraud', 'detection'],
    completionRate: 0,
    rating: 4.8,
  },
  {
    id: 'tr_003',
    title: 'Decision Making Framework',
    description: 'Develop a structured approach to making consistent, high-quality decisions.',
    type: 'article',
    category: 'decision_quality',
    duration: 20,
    difficulty: 'intermediate',
    url: 'https://example.com/training/decision-framework',
    tags: ['decision', 'framework', 'quality'],
    completionRate: 0,
    rating: 4.6,
  },
  {
    id: 'tr_004',
    title: 'Time Management Mastery',
    description: 'Optimize your time management to handle workload effectively.',
    type: 'webinar',
    category: 'workload_management',
    duration: 45,
    difficulty: 'beginner',
    url: 'https://example.com/training/time-management',
    tags: ['time', 'management', 'productivity'],
    completionRate: 0,
    rating: 4.4,
  },
  {
    id: 'tr_005',
    title: 'Communication Excellence',
    description: 'Improve your communication skills for better stakeholder engagement.',
    type: 'case_study',
    category: 'communication',
    duration: 25,
    difficulty: 'intermediate',
    url: 'https://example.com/training/communication',
    tags: ['communication', 'skills', 'engagement'],
    completionRate: 0,
    rating: 4.7,
  },
];
