package ink.wgink.login.base.controller.api.login;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.login.base.pojo.dtos.login.LoginFormDTO;
import ink.wgink.login.base.pojo.vos.login.LoginFormVO;
import ink.wgink.login.base.service.login.ILoginFormService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultList;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: LoginFormController
 * @Description: 登录表单
 * @Author: wanggeng
 * @Date: 2021/7/29 4:06 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "登录表单")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/login-form")
public class LoginFormController extends DefaultBaseController {

    @Autowired
    private ILoginFormService loginFormService;
    
    @ApiOperation(value = "新增登录Form", notes = "新增登录Form接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("save")
    @CheckRequestBodyAnnotation
    public SuccessResult save(@RequestBody LoginFormVO loginFormVO) {
        loginFormService.save(loginFormVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "删除登录Form", notes = "删除登录Form接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "登录FormID列表，用下划线分隔", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @DeleteMapping("remove/{ids}")
    public SuccessResult remove(@PathVariable("ids") String ids) {
        loginFormService.remove(Arrays.asList(ids.split("\\_")));
        return new SuccessResult();
    }

    @ApiOperation(value = "修改登录Form", notes = "修改登录Form接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "loginFormId", value = "登录FormID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update/{loginFormId}")
    @CheckRequestBodyAnnotation
    public SuccessResult update(@PathVariable("loginFormId") String loginFormId, @RequestBody LoginFormVO loginFormVO) {
        loginFormService.update(loginFormId, loginFormVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "激活登录Form", notes = "激活登录Form接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "loginFormId", value = "登录FormID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update-active/{loginFormId}")
    public SuccessResult updateActive(@PathVariable("loginFormId") String loginFormId) {
        loginFormService.updateActive(loginFormId);
        return new SuccessResult();
    }

    @ApiOperation(value = "取消激活登录Form", notes = "取消激活登录Form接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "loginFormId", value = "登录FormID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update-un-active/{loginFormId}")
    public SuccessResult updateUnActive(@PathVariable("loginFormId") String loginFormId) {
        loginFormService.updateUnActive(loginFormId);
        return new SuccessResult();
    }

    @ApiOperation(value = "登录Form列表", notes = "登录Form列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list")
    public List<LoginFormDTO> list() {
        Map<String, Object> params = requestParams();
        return loginFormService.list(params);
    }

    @ApiOperation(value = "登录Form分页列表", notes = "登录Form分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage")
    public SuccessResultList<List<LoginFormDTO>> listPage(ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return loginFormService.listPage(page);
    }

    @ApiOperation(value = "登录Form详情", notes = "登录Form详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "loginFormId", value = "登录FormID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("get/{loginFormId}")
    public LoginFormDTO getUser(@PathVariable("loginFormId") String loginFormId) {
        return loginFormService.get(loginFormId);
    }
    
}
