package com.yihu.hos.standard.controller;

import com.yihu.hos.standard.service.adapter.AdapterSchemeService;
import com.yihu.hos.web.framework.model.DetailModelResult;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.controller.BaseController;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController("SchemeController")
@RequestMapping("/adapterCenter")
//@Api(protocols = "https", value = "SchemeController", description = "适配方案管理", tags = {"适配方案"})
public class SchemeController extends BaseController {
    @Resource(name = AdapterSchemeService.BEAN_ID)
    private AdapterSchemeService adapterSchemeService;
    /**
     * 查询适配方案首页信息（get）
     * @param condition
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/searchScheme")
    @ApiOperation(value = "获取方案列表", response = DetailModelResult.class, responseContainer = "List", notes = "获取方案列表")
    public DetailModelResult searchScheme(
            @ApiParam(name = "condition", value = "查询条件：适配方案名称、适配方案版本名称")
            @RequestParam(value = "condition", required = false) String condition) {
        return adapterSchemeService.getSchemeList(condition);
    }

    /**
     * 根据适配ID获取适配方案信息（get）
     * @param schemeId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getForSchemeId")
    @ApiOperation(value = "获取适配方案", response = Result.class, produces = "application/json", notes = "获取适配方案")
    public Result get(
            @ApiParam(name = "schemeId", value = "标准版本ID")
            @RequestParam(value = "schemeId") Integer schemeId) {
        return adapterSchemeService.get(schemeId);
    }

    /**
     * 修改适配（PUT）
     * @param scheme
     * @return
     * @throws Exception
     */
    @RequestMapping("/updateScheme")
    @ApiOperation(value = "修改适配方案", response = Result.class, produces = "application/json", notes = "修改适配方案")
    public Result modify(
            @ApiParam(name = "scheme", value = "适配方案")
            @RequestParam(value = "scheme") String scheme) {
        return adapterSchemeService.update(scheme);
    }

    /**
     * 新增适配（POST）
     * @param scheme
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/addScheme")
    @ApiOperation(value = "保存适配方案", response = Result.class, produces = "application/json", notes = "保存适配方案")
    public Result add(
            @ApiParam(name = "scheme", value = "适配方案信息")
            @RequestParam(value = "scheme") String scheme) {
        return adapterSchemeService.add(scheme);
    }

    /**
     * 删除适配（DELETE）
     * @param  schemeId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/deleteScheme")
    @ApiOperation(value = "删除适配方案", response = Result.class, produces = "application/json", notes = "删除适配方案")
    public Result delete(
            @ApiParam(name = "schemeId", value = "适配方案ID")
            @RequestParam(value = "schemeId") Integer schemeId) {
        return adapterSchemeService.delete(schemeId);
    }
}
