/**
 * 테스트용 더미 데이터
 *
 * 테스트에서 재사용 가능한 모킹 데이터
 */

// 사용자 더미 데이터
const mockUsers = {
  admin: {
    id: 1,
    username: 'admin',
    role: 'admin',
    access_level: 5
  },
  groupLeader: {
    id: 2,
    username: 'group_leader',
    role: 'group_leader',
    access_level: 3
  },
  worker: {
    id: 3,
    username: 'worker',
    role: 'worker',
    access_level: 1
  }
};

// 작업자 더미 데이터
const mockWorkers = [
  {
    worker_id: 1,
    worker_name: '김철수',
    job_type: 'developer',
    is_active: 1,
    created_at: '2025-01-01 00:00:00'
  },
  {
    worker_id: 2,
    worker_name: '이영희',
    job_type: 'designer',
    is_active: 1,
    created_at: '2025-01-01 00:00:00'
  },
  {
    worker_id: 3,
    worker_name: '박민수',
    job_type: 'developer',
    is_active: 0,
    created_at: '2025-01-01 00:00:00'
  }
];

// 프로젝트 더미 데이터
const mockProjects = [
  {
    project_id: 1,
    project_name: '프로젝트 A',
    job_no: 'PRJ-001',
    created_at: '2025-01-01 00:00:00'
  },
  {
    project_id: 2,
    project_name: '프로젝트 B',
    job_no: 'PRJ-002',
    created_at: '2025-01-15 00:00:00'
  }
];

// 작업 유형 더미 데이터
const mockWorkTypes = [
  { id: 1, name: '개발' },
  { id: 2, name: '디자인' },
  { id: 3, name: '테스트' },
  { id: 4, name: '회의' }
];

// 에러 유형 더미 데이터
const mockErrorTypes = [
  { id: 1, name: '버그 수정' },
  { id: 2, name: '재작업' },
  { id: 3, name: '긴급 수정' }
];

// 작업 보고서 더미 데이터
const mockWorkReports = [
  {
    id: 1,
    report_date: '2025-12-11',
    worker_id: 1,
    project_id: 1,
    work_type_id: 1,
    work_hours: 8.0,
    work_content: '기능 개발',
    error_type_id: null,
    work_status_id: 1,
    created_by: 1,
    created_at: '2025-12-11 09:00:00',
    updated_at: '2025-12-11 09:00:00'
  },
  {
    id: 2,
    report_date: '2025-12-11',
    worker_id: 2,
    project_id: 1,
    work_type_id: 2,
    work_hours: 7.5,
    work_content: 'UI 디자인',
    error_type_id: null,
    work_status_id: 1,
    created_by: 2,
    created_at: '2025-12-11 09:00:00',
    updated_at: '2025-12-11 09:00:00'
  },
  {
    id: 3,
    report_date: '2025-12-11',
    worker_id: 1,
    project_id: 2,
    work_type_id: 1,
    work_hours: 2.0,
    work_content: '버그 수정',
    error_type_id: 1,
    work_status_id: 2,
    created_by: 1,
    created_at: '2025-12-11 14:00:00',
    updated_at: '2025-12-11 14:00:00'
  }
];

// 출석 더미 데이터
const mockAttendance = [
  {
    id: 1,
    worker_id: 1,
    attendance_date: '2025-12-11',
    status: 'work',
    regular_hours: 8.0,
    overtime_hours: 0.0,
    created_by: 1,
    created_at: '2025-12-11 09:00:00'
  },
  {
    id: 2,
    worker_id: 2,
    attendance_date: '2025-12-11',
    status: 'vacation',
    regular_hours: 0.0,
    overtime_hours: 0.0,
    created_by: 2,
    created_at: '2025-12-11 09:00:00'
  }
];

// 분석 데이터 더미
const mockAnalysisData = {
  summary: {
    total_entries: 100,
    total_hours: 800.0,
    unique_workers: 10,
    unique_projects: 5,
    working_days: 20,
    avg_hours_per_entry: 8.0,
    contributors: 3,
    error_entries: 5,
    error_rate: 5.0
  },
  dailyStats: [
    { report_date: '2025-12-01', daily_hours: 40.0, daily_entries: 5, daily_workers: 5 },
    { report_date: '2025-12-02', daily_hours: 35.0, daily_entries: 5, daily_workers: 4 }
  ]
};

// API 응답 형식
const createSuccessResponse = (data, message = '성공') => ({
  success: true,
  data,
  message
});

const createErrorResponse = (error, message = '오류 발생') => ({
  success: false,
  error,
  message
});

// 날짜 헬퍼
const createDateString = (daysFromToday = 0) => {
  const date = new Date();
  date.setDate(date.getDate() + daysFromToday);
  return date.toISOString().split('T')[0];
};

// DB 쿼리 결과 모킹 헬퍼
const createDbResult = (data, affectedRows = 1, insertId = 1) => {
  if (Array.isArray(data)) {
    return [data, []]; // [rows, fields]
  }
  return [
    {
      affectedRows,
      insertId,
      changedRows: affectedRows
    },
    []
  ];
};

module.exports = {
  // 더미 데이터
  mockUsers,
  mockWorkers,
  mockProjects,
  mockWorkTypes,
  mockErrorTypes,
  mockWorkReports,
  mockAttendance,
  mockAnalysisData,

  // 헬퍼 함수
  createSuccessResponse,
  createErrorResponse,
  createDateString,
  createDbResult
};
