package com.ruoyi.web.controller.base;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.base.protocol.domain.bo.ProtocolBo;
import com.ruoyi.base.protocol.domain.vo.ProtocolVo;
import com.ruoyi.base.protocol.service.IProtocolService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.FilePathSplicingType;
import com.ruoyi.common.filepathsplicing.FilePathSplicing;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 协议管理Controller
 *
 * @author xiechao
 * @date 2023-12-21
 */
@Validated
@Api(value = "协议管理控制器", tags = {"协议管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/protocol")
public class ProtocolController extends BaseController {

    private final IProtocolService iProtocolService;




    /**
     * 通过协议code获取协议详细信息
     */
    @FilePathSplicing(type = FilePathSplicingType.RESPONSE)
    @ApiOperation("通过协议code获取协议详细信息")
    @SaCheckPermission("protocol:protocol:query")
    @GetMapping("/info/{code}")
    public R<ProtocolVo> getInfo(@ApiParam("协议code") @NotNull(message = "协议code不能为空") @PathVariable("code") String  code) {
        return R.ok(iProtocolService.getByProtocolCode(code));
    }

    /**
     * 保存协议管理
     */
    @FilePathSplicing(type = FilePathSplicingType.REQUEST)
    @ApiOperation("保存协议管理")
    @SaCheckPermission("protocol:protocol:save")
    @Log(title = "协议管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/save")
    public R<Void> save(@Validated(EditGroup.class) @RequestBody ProtocolBo bo) {
        return toAjax(iProtocolService.save(bo) ? 1 : 0);
    }

}
