package org.springblade.modules.app.web;


import org.springblade.common.auth.permission.DisableLoginVerify;
import com.wn.common.controller.BaseController;
import com.wn.common.datamodel.ResultDTO;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.modules.app.aspect.ClientLogin;
import org.springblade.modules.app.common.dto.SlaughterBuyerRelationDTO;
import org.springblade.modules.app.common.dto.UnbindRelationDTO;
import org.springblade.modules.app.common.dto.UserDTO;
import org.springblade.modules.app.manager.SlaughterBuyerRelationManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 代宰户与屠宰场绑定关系表 前端控制器
 * </p>
 *
 * @author zhangK
 * @since 2022-01-13
 */
@RestController
@RequestMapping("app/relation")
@Api(value = "代、屠绑定关系", tags = "代、屠绑定关系")
public class SlaughterBuyerRelationController extends BaseController {

    @Autowired
    private SlaughterBuyerRelationManager slaughterBuyerRelationManager;

    @Autowired
    private BladeRedis bladeRedis;

    //@ApiOperation(value = "查询绑定列表(代、屠共用)")
    @GetMapping("/list")
    @ApiImplicitParam(name = "state", value = "状态 0-待确认 1-已绑定 9-已拒绝", required = true)
    @DisableLoginVerify
//    @ClientLogin
    public ResponseEntity<ResultDTO<List<SlaughterBuyerRelationDTO>>> list(Integer state, @ApiIgnore String token) {
        return success(slaughterBuyerRelationManager.list(state, token));
    }


    //@ApiOperation(value = "绑定（代绑屠）")
    @PostMapping("/bind/{name}")
    @ApiImplicitParam(name = "name", value = "屠宰场名称", required = true)
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<Boolean>> bind(@PathVariable String name, @ApiIgnore UserDTO userDTO) {
        return success(slaughterBuyerRelationManager.bind(name, userDTO));
    }


    //@ApiOperation(value = "解绑(代、屠共用)")
    @PostMapping("/unbind")
    @DisableLoginVerify
    @ClientLogin
    public ResponseEntity<ResultDTO<Boolean>> unbind(@RequestBody UnbindRelationDTO dto, @ApiIgnore UserDTO userDTO) {
        return success(slaughterBuyerRelationManager.unbind(dto, userDTO));
    }

    //@ApiOperation(value = "是否自动审批")
    @PutMapping("/auto/apply")
    @ClientLogin
    public ResponseEntity<ResultDTO<Boolean>> autoApply(@RequestBody SlaughterBuyerRelationDTO slaughterBuyerRelationDTO, @ApiIgnore UserDTO userDTO) {
        return success(slaughterBuyerRelationManager.autoApply(slaughterBuyerRelationDTO, userDTO));
    }


    //@ApiOperation(value = "登录校验绑定屠宰场")
    @GetMapping("/check/ifBind")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<Boolean>> checkIfBind() {
        return success(true);
    }

}

