package org.dromara.system.controller;

import cn.idev.excel.EasyExcel;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.context.WriteContext;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.ibatis.javassist.bytecode.AnnotationsAttribute;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.EnrollProjectVo;
import org.dromara.system.domain.vo.GameAthleteVo;
import org.dromara.system.service.IEnrollService;
import org.dromara.system.service.IGameEventProjectService;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 报名
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/enroll")
public class EnrollController {

    private final IEnrollService enrollService;

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletRequest request, HttpServletResponse response, Long eventId) throws IOException {
        enrollService.downloadTemplateForPoi(request, response, eventId);
    }


    /**
     * 导入报名表
     */
    @PostMapping("/importData/{eventId}")
    public R<String> importData(
        @RequestParam("file") MultipartFile file,
        @PathVariable Long eventId) {
        Boolean result = enrollService.importDataForPoi(file, eventId);
        return R.ok(result ? "导入成功" : "导入失败");
    }
}
