package com.smppw.modaq.application.api;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.smppw.modaq.application.service.EmailParseApiService;
import com.smppw.modaq.domain.dto.UploadReportParams;
import com.smppw.modaq.domain.dto.UploadReportResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/daq-parse")
public class ParseApi {
    private final EmailParseApiService service;

    public ParseApi(EmailParseApiService service) {
        this.service = service;
    }

    @GetMapping("report")
    public ResponseEntity<String> report(String startDateTime) {
        Date now = new Date();
        Date preDate;
        if (StrUtil.isBlank(startDateTime)) {
            preDate = DateUtil.offsetDay(now, -1);
        } else {
            preDate = DateUtil.parseDateTime(startDateTime);
        }
        this.service.parseEmail(preDate, now, null, null);
        return ResponseEntity.ok("success");
    }

    @GetMapping("reparse")
    public ResponseEntity<String> reparseReport(Integer emailId) {
        this.service.reparseEmail(emailId);
        return ResponseEntity.ok("success");
    }

    @PostMapping("upload-parse")
    public ResponseEntity<List<UploadReportResult>> uploadReport(@RequestBody UploadReportParams params) {
        return null;
    }
}
