package cn.com.tenlion.configcolumn.controller.app.api.configcolumndata;

import cn.com.tenlion.configcolumn.service.configcolumn.IConfigColumnService;
import cn.com.tenlion.configtable.pojo.dtos.configtableoperation.ConfigTableOperationDTO;
import cn.com.tenlion.configtable.pojo.dtos.configtableoperation.ConfigTableOperationGroupDTO;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: ConfigColumnDataAppController
 * @Description:
 * @Author: CodeFactory
 * @Date: 2021-06-26 13:49:46
 * @Version: 3.0
 **/
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "接口", value = "栏目动态数据")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/configcolumndata")
public class ConfigColumnDataAppController extends DefaultBaseController {

    @Autowired
    private IConfigColumnService configColumnService;

    @ApiOperation(value = "动态字段列表", notes = "动态字段列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listfield/{configColumnId}")
    public List<ConfigTableOperationDTO> listConfig(@RequestHeader("token") String token, @PathVariable("configColumnId") String configColumnId) {
        return configColumnService.listFieldConfig(token, configColumnId);
    }
/*
    无用接口 2021年7月1日18:10:10 崔宝铖
    @ApiOperation(value = "我的栏目数据列表", notes = "我的栏目数据列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listcode/{configColumnCode}")
    public List<ConfigTableOperationGroupDTO> listDataByCode(@RequestHeader("token") String token, @PathVariable("configColumnCode") String configColumnCode) {
        Map<String, Object> params = requestParams();
        return configColumnService.listDataByCode(token, configColumnCode, params);
    }
*/

    @ApiOperation(value = "我的栏目数据列表(传入userId加载指定用户的栏目数据,不传入则使用token用户)", notes = "我的栏目数据列表接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "token", value = "token", paramType = "header")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list/{configColumnId}")
    public List<ConfigTableOperationGroupDTO> list(@RequestHeader("token") String token, @PathVariable("configColumnId") String configColumnId) {
        Map<String, Object> params = requestParams();
        return configColumnService.listData(token, configColumnId, params);
    }

    @ApiOperation(value = "栏目动态数据(通过ID)", notes = "栏目动态数据(通过ID)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "configColumnId", value = "ID", paramType = "path"),
            @ApiImplicitParam(name = "uid", value = "ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("get/{configColumnId}/{uid}")
    public ConfigTableOperationGroupDTO  get(@RequestHeader("token") String token, @PathVariable("configColumnId") String configColumnId, @PathVariable("uid") String uid) {
        return configColumnService.getData(token, configColumnId, uid);
    }

    @ApiOperation(value = "新增或修改栏目动态数据", notes = "新增栏目动态数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "params", value = "params", paramType = "header")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("save/{configColumnId}")
    public SuccessResultData<String> saveData(@RequestHeader("token") String token, @PathVariable("configColumnId") String configColumnId, @RequestBody Map<String, Object> params) {
        String uid = configColumnService.saveData(token, configColumnId, params);
        return new SuccessResultData(uid);
    }

    @ApiOperation(value = "删除栏目动态数据", notes = "删除栏目动态数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @DeleteMapping("delete/{configColumnId}/{uid}")
    public SuccessResult saveData(@RequestHeader("token") String token, @PathVariable("configColumnId") String configColumnId, @PathVariable("uid") String uid) {
        configColumnService.deleteData(token, configColumnId, uid);
        return new SuccessResult();
    }

}