package com.jiayue.ipfcst.fileupload.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.constant.enums.FeedbackFileStatusEnum;
import com.jiayue.ipfcst.common.data.entity.FeedbackFileLog;
import com.jiayue.ipfcst.fileupload.service.FeedbackFileLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("feedbackFileLog")
@Slf4j
public class FeedbackFileLogController {
  @Autowired FeedbackFileLogService feedbackFileLogService;

  @GetMapping
  public ResponseVO getAll(){
    return  ResponseVO.success(feedbackFileLogService.getAll());
  }

  @GetMapping("/getFeedbackFileStatusEnum")
  public ResponseVO getFeedbackFileStatus(){
    List list = new ArrayList<>();
    for (FeedbackFileStatusEnum fileStatusEnum : FeedbackFileStatusEnum.values()) {
      Map map = new HashMap();
      map.put("name", fileStatusEnum.name());
      map.put("code", fileStatusEnum.getCode());
      map.put("message", fileStatusEnum.getMessage());
      list.add(map);
    }
    return ResponseVO.success(list);
  }

  @GetMapping("/{uploadObjectId}/{fileTime}/{fileType}/{fileStatus}")
  public ResponseVO getByFileTimeAndUploadObjectNoAndFileType(@PathVariable("uploadObjectId") Integer uploadObjectId, @PathVariable("fileTime") String fileTime,
    @PathVariable("fileType") String fileType, @PathVariable("fileStatus") String fileStatus) {
    List<FeedbackFileLog> feedbackFileLogList = feedbackFileLogService.getByFileTimeAndUploadObjectNoAndFileType(uploadObjectId,fileTime,fileType,fileStatus);
    return ResponseVO.success(feedbackFileLogList);
  }
}
