package com.jumeirah.api.merchant.controller;

import com.jumeirah.common.param.MerchantLoginParam;
import com.jumeirah.common.service.MerchantService;
import com.jumeirah.common.service.MerchantUserService;
import com.jumeirah.common.vo.LoginMerUserTokenVo;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLogIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 商家用户 控制器
 *
 * @author wei
 * @since 2020-09-27
 */
@Slf4j
@RestController
@RequestMapping("/merchant/user")
@Module("${cfg.module}")
@Api(value = "商家用户API", tags = {"商家用户表"})
public class MerchantUserController extends BaseController {

    @Autowired
    private MerchantUserService merchantUserService;
    @Autowired
    private MerchantService merchantService;

//    /**
//     * 添加商家用户
//     */
//    @PostMapping("/add")
//    @OperationLog(name = "添加商家用户", type = OperationLogType.ADD)
//    @ApiOperation(value = "添加商家用户", response = ApiResult.class)
//    public ApiResult<Boolean> addMerchantUser(@Validated(Add.class) @RequestBody MerchantUser merchantUser) throws Exception {
//        boolean flag = merchantUserService.saveMerchantUser(merchantUser);
//        return ApiResult.result(flag);
//    }
//
//    /**
//     * 修改商家用户
//     */
//    @PostMapping("/update")
//    @OperationLog(name = "修改商家用户", type = OperationLogType.UPDATE)
//    @ApiOperation(value = "修改商家用户", response = ApiResult.class)
//    public ApiResult<Boolean> updateMerchantUser(@Validated(Update.class) @RequestBody MerchantUser merchantUser) throws Exception {
//        boolean flag = merchantUserService.updateMerchantUser(merchantUser);
//        return ApiResult.result(flag);
//    }
//
//    /**
//     * 删除商家用户
//     */
//    @PostMapping("/delete/{id}")
//    @OperationLog(name = "删除商家用户", type = OperationLogType.DELETE)
//    @ApiOperation(value = "删除商家用户", response = ApiResult.class)
//    public ApiResult<Boolean> deleteMerchantUser(@PathVariable("id") Long id) throws Exception {
//        boolean flag = merchantUserService.deleteMerchantUser(id);
//        return ApiResult.result(flag);
//    }
//
//    /**
//     * 获取商家用户详情
//     */
//    @GetMapping("/info/{id}")
//    @OperationLog(name = "商家用户详情", type = OperationLogType.INFO)
//    @ApiOperation(value = "商家用户详情", response = MerchantUserQueryVo.class)
//    public ApiResult<MerchantUserQueryVo> getMerchantUser(@PathVariable("id") Long id) throws Exception {
//        MerchantUserQueryVo merchantUserQueryVo = merchantUserService.getMerchantUserById(id);
//        return ApiResult.ok(merchantUserQueryVo);
//    }
//
//    /**
//     * 商家用户分页列表
//     */
//    @PostMapping("/getPageList")
//    @OperationLog(name = "商家用户分页列表", type = OperationLogType.PAGE)
//    @ApiOperation(value = "商家用户分页列表", response = MerchantUserQueryVo.class)
//    public ApiResult<Paging<MerchantUserQueryVo>> getMerchantUserPageList(@Validated @RequestBody MerchantUserPageParam merchantUserPageParam) throws Exception {
//        Paging<MerchantUserQueryVo> paging = merchantUserService.getMerchantUserPageList(merchantUserPageParam);
//        return ApiResult.ok(paging);
//    }

    @PostMapping("/login")
    @OperationLogIgnore
    @ApiOperation(value = "登录", notes = "商家用户登录")
    public ApiResult<LoginMerUserTokenVo> login(@Validated @RequestBody MerchantLoginParam merchantLoginParam, HttpServletResponse response) throws Exception {
        return merchantUserService.login(merchantLoginParam);
    }

//    @PostMapping("/register")
//    @OperationLogIgnore
//    @ApiOperation(value = "注册", notes = "商家注册")
//    public ApiResult<Boolean> register(@Validated @RequestBody MerchantRegisterParam merchantRegisterParam, HttpServletResponse response) throws Exception {
//        return merchantUserService.register(merchantRegisterParam);
//    }
}

