/**
 * Skill Matrix types for tOS LEAN module
 */

/**
 * Skill level numeric values (0-4)
 * Based on LEAN competency matrix standards
 */
export type SkillLevelValue = 0 | 1 | 2 | 3 | 4;

/**
 * Skill level labels
 */
export const SKILL_LEVEL_LABELS: Record<SkillLevelValue, string> = {
  0: 'Keine Kenntnisse',
  1: 'Grundlagen',
  2: 'Selbststaendig',
  3: 'Experte',
  4: 'Kann schulen',
};

/**
 * Skill level labels in English
 */
export const SKILL_LEVEL_LABELS_EN: Record<SkillLevelValue, string> = {
  0: 'No knowledge',
  1: 'Basic understanding',
  2: 'Independent work',
  3: 'Expert',
  4: 'Can train others',
};

/**
 * Skill level colors for visual display
 * Following LEAN traffic light convention
 */
export const SKILL_LEVEL_COLORS: Record<SkillLevelValue, string> = {
  0: 'bg-gray-200 text-gray-700',
  1: 'bg-red-500 text-white',
  2: 'bg-yellow-500 text-black',
  3: 'bg-green-500 text-white',
  4: 'bg-blue-500 text-white',
};

/**
 * Skill level badge variants
 */
export const SKILL_LEVEL_VARIANTS: Record<SkillLevelValue, 'default' | 'secondary' | 'destructive' | 'warning' | 'success'> = {
  0: 'secondary',
  1: 'destructive',
  2: 'warning',
  3: 'success',
  4: 'default',
};

/**
 * Skill categories
 */
export type SkillCategory = 'technical' | 'softSkills' | 'processes' | 'safety' | 'quality' | 'other';

/**
 * Skill category labels
 */
export const SKILL_CATEGORY_LABELS: Record<SkillCategory, string> = {
  technical: 'Technisch',
  softSkills: 'Soft Skills',
  processes: 'Prozesse',
  safety: 'Sicherheit',
  quality: 'Qualitaet',
  other: 'Sonstige',
};

/**
 * Skill interface
 */
export interface Skill {
  id: string;
  name: string;
  description?: string | null;
  category?: string | null;
  departmentId?: string | null;
  isActive: boolean;
  createdAt: Date;
  updatedAt: Date;
  department?: {
    id: string;
    name: string;
    code?: string | null;
  } | null;
  _count?: {
    entries: number;
  };
}

/**
 * Skill matrix entry (assessment)
 */
export interface SkillMatrixEntry {
  id: string;
  employeeId: string;
  skillId: string;
  level: SkillLevelValue;
  assessedAt: Date;
  assessedById?: string | null;
  notes?: string | null;
  nextReview?: Date | null;
  employee?: {
    id: string;
    employeeNumber: string;
    position: string;
    user: {
      id: string;
      firstName: string;
      lastName: string;
      email: string;
    };
  };
  skill?: Skill;
  assessedBy?: {
    id: string;
    firstName: string;
    lastName: string;
  } | null;
}

/**
 * Employee skill data in matrix view
 */
export interface EmployeeSkillData {
  level: number;
  assessedAt: Date | null;
  assessedBy: {
    id: string;
    firstName: string;
    lastName: string;
  } | null;
  notes: string | null;
}

/**
 * Matrix row (employee with skills)
 */
export interface MatrixRow {
  employee: {
    id: string;
    employeeNumber: string;
    position: string;
    user: {
      id: string;
      firstName: string;
      lastName: string;
      email: string;
    };
  };
  skills: Record<string, EmployeeSkillData>;
}

/**
 * Skill matrix data structure
 */
export interface SkillMatrix {
  department: {
    id: string;
    name: string;
    code?: string | null;
  };
  skills: Array<{
    id: string;
    name: string;
    description?: string | null;
    category?: string | null;
    isGlobal: boolean;
  }>;
  matrix: MatrixRow[];
}

/**
 * Skill gap analysis result
 */
export interface SkillGapAnalysis {
  skillId: string;
  skillName: string;
  category: string | null;
  targetLevel: number;
  averageLevel: number;
  gap: number;
  employeesBelow: number;
  employeesAtOrAbove: number;
  totalEmployees: number;
}

/**
 * Skill coverage result
 */
export interface SkillCoverage {
  skillId: string;
  skillName: string;
  levelDistribution: Record<number, number>;
  totalAssessed: number;
  coverage: number;
  averageLevel: number;
}

/**
 * Trainer info for a skill
 */
export interface SkillTrainer {
  employeeId: string;
  employeeNumber: string;
  position: string;
  user: {
    id: string;
    firstName: string;
    lastName: string;
    email: string;
    department?: {
      id: string;
      name: string;
    } | null;
  };
  assessedAt: Date;
}

/**
 * Trainers for a skill result
 */
export interface SkillTrainers {
  skill: {
    id: string;
    name: string;
    category: string | null;
  };
  trainers: SkillTrainer[];
  totalTrainers: number;
}

/**
 * Create skill DTO
 */
export interface CreateSkillDto {
  name: string;
  description?: string;
  category?: SkillCategory;
  departmentId?: string;
  targetLevel?: SkillLevelValue;
  isActive?: boolean;
}

/**
 * Update skill DTO
 */
export interface UpdateSkillDto {
  name?: string;
  description?: string;
  category?: SkillCategory;
  departmentId?: string;
  targetLevel?: SkillLevelValue;
  isActive?: boolean;
}

/**
 * Create skill entry DTO
 */
export interface CreateSkillEntryDto {
  employeeId: string;
  skillId: string;
  level: SkillLevelValue;
  notes?: string;
  nextReview?: string;
}

/**
 * Update skill entry DTO
 */
export interface UpdateSkillEntryDto {
  level?: SkillLevelValue;
  notes?: string;
  nextReview?: string;
}

/**
 * Bulk skill entry DTO
 */
export interface BulkSkillEntryDto {
  entries: CreateSkillEntryDto[];
}
