package com.red.circle.console.adapter.app.approval;

import com.red.circle.common.business.core.enums.ApprovalStatusEnum;
import com.red.circle.console.app.dto.cmd.app.props.ApprovalContentDTO;
import com.red.circle.console.app.service.app.approval.ApprovalReportedService;
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.inner.model.cmd.approval.ApprovalReportedCmd;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
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;

/**
 * 举报审核
 *
 * @author pengliang on 2020/9/22
 */
@RestController
@RequestMapping("/approval/reported")
@AllArgsConstructor
public class ApprovalReportedRestController extends BaseController {

  private final ApprovalReportedService approvalReportedService;

  @OpsOperationReqLog("举报审批-通过")
  @PostMapping("/pass")
  public void approvalPass(@RequestBody List<ApprovalContentDTO> params) {

    approvalReportedService.approvalReported(
        new ApprovalReportedCmd().setApprovalStatus(ApprovalStatusEnum.PASS.name())
            .setApprovalUserId(getReqUserId())
            .setContentIds(params.stream().map(ApprovalContentDTO::getContentId).collect(
                Collectors.toList())));
  }

  @OpsOperationReqLog("举报审批-不通过")
  @PostMapping("/not/pass")
  public void approvalNotPass(@RequestBody List<ApprovalContentDTO> params) {
    approvalReportedService.approvalReported(
        new ApprovalReportedCmd().setApprovalStatus(ApprovalStatusEnum.NOT_PASS.name())
            .setApprovalUserId(getReqUserId())
            .setContentIds(params.stream().map(ApprovalContentDTO::getContentId).collect(
                Collectors.toList())));
  }
}
