package com.arms.api.report.rolling3m.controller;

import com.arms.api.report.rolling3m.assignee.model.dto.Rolling3mDTO;
import com.arms.api.report.rolling3m.model.vo.Rolling3mAssigneeReportVO;
import com.arms.api.report.rolling3m.model.vo.Rolling3mReportVO;
import com.arms.api.report.rolling3m.service.Rolling3mReportService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/report/rolling3m")
@AllArgsConstructor
@Slf4j
public class Rolling3mReportController {

    private final Rolling3mReportService rolling3mReportService;

    @PostMapping("/assignee")
    public ResponseEntity<Rolling3mAssigneeReportVO> rolling3mReportByAssignee(@RequestBody Rolling3mDTO rolling3mDTO) {

        if (rolling3mDTO.getPdServiceId() == null || ObjectUtils.isEmpty(rolling3mDTO.getPdServiceVersions())) {
            log.warn("Rolling3mReportController :: rolling3mReportByAssignee | 제품/서비스 아이디 또는 버전 정보가 없습니다.");
            return ResponseEntity.badRequest().build();
        }

        if (StringUtils.isEmpty(rolling3mDTO.getAssigneeId())) {
            log.warn("Rolling3mReportController :: rolling3mReportByAssignee | 담당자의 accountId가 없습니다.");
            return ResponseEntity.badRequest().build();
        }

        return ResponseEntity.ok(rolling3mReportService.rolling3mReportByAssignee(rolling3mDTO));
    }

    @PostMapping
    public ResponseEntity<Rolling3mReportVO> rolling3mReport(@RequestBody Rolling3mDTO rolling3mDTO) {

        if (rolling3mDTO.getPdServiceId() == null || ObjectUtils.isEmpty(rolling3mDTO.getPdServiceVersions())) {
            log.warn("Rolling3mReportController :: rolling3mReportByAssignee | 제품/서비스 아이디 또는 버전 정보가 없습니다.");
            return ResponseEntity.badRequest().build();
        }

        return ResponseEntity.ok(rolling3mReportService.rolling3mReport(rolling3mDTO));
    }

}
