package com.tofly.qualitycontrol.controller;

import com.tofly.common.core.entity.ResultRespone;
import com.tofly.qualitycontrol.entity.RejectedCountConfig;
import com.tofly.qualitycontrol.service.IRejectedCountConfigService;
import com.tofly.qualitycontrol.util.QualityControlUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.tofly.qualitycontrol.common.QualityControlConstant.FAILED;
import static com.tofly.qualitycontrol.common.QualityControlConstant.SUCCESS;

/**
 * 驳回次数配置接口控制器
 *
 * @author B
 */
@RestController
@RequestMapping("/rejectedCountConfig")
@Api(value = "驳回次数配置接口", tags = "驳回次数配置接口")
@RequiredArgsConstructor
public class RejectedCountConfigController {

	private final IRejectedCountConfigService service;

	@ApiOperation(value = "驳回次数配置列表", notes = "", httpMethod = "GET")
	@GetMapping("/list")
	public ResultRespone<List<RejectedCountConfig>> list() {
		return ResultRespone.success(service.list(),SUCCESS);
	}

	@ApiOperation(value = "配置驳回次数", notes = "只修改次数", httpMethod = "POST")
	@PostMapping("/config")
	public ResultRespone config(@Validated @RequestBody RejectedCountConfig rejectedCountConfig,BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ResultRespone.failed(QualityControlUtil.getErrorStrings(bindingResult),FAILED);
		}
		Boolean flag = service.updateById(rejectedCountConfig);
		return flag ? ResultRespone.success(flag,SUCCESS) : ResultRespone.failed(flag,FAILED);
	}

}
