/**
 * 일일 이슈 보고서 관리 컨트롤러
 *
 * 일일 이슈 보고서 CRUD API 엔드포인트 핸들러
 *
 * @author TK-FB-Project
 * @since 2025-12-11
 */

const dailyIssueReportService = require('../services/dailyIssueReportService');
const { asyncHandler } = require('../middlewares/errorHandler');

/**
 * 일일 이슈 보고서 생성
 */
const createDailyIssueReport = asyncHandler(async (req, res) => {
  // 프론트엔드에서 user_ids 또는 user_id로 보낼 수 있음
  const issueData = {
    ...req.body,
    user_ids: req.body.user_ids || req.body.user_id
  };

  const result = await dailyIssueReportService.createDailyIssueReportService(issueData);

  res.status(201).json({
    success: true,
    data: result,
    message: result.message
  });
});

/**
 * 날짜별 이슈 조회
 */
const getDailyIssuesByDate = asyncHandler(async (req, res) => {
  const { date } = req.query;
  const issues = await dailyIssueReportService.getDailyIssuesByDateService(date);

  res.json({
    success: true,
    data: issues,
    message: '이슈 보고서 조회 성공'
  });
});

/**
 * 이슈 보고서 삭제
 */
const removeDailyIssue = asyncHandler(async (req, res) => {
  const { id } = req.params;
  const result = await dailyIssueReportService.removeDailyIssueService(id);

  res.json({
    success: true,
    data: result,
    message: result.message
  });
});

module.exports = {
  createDailyIssueReport,
  getDailyIssuesByDate,
  removeDailyIssue
};
