package cn.pluss.platform.controller.merchantBaseInfo;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.entity.MerchantBaseInfo;
import cn.pluss.platform.entity.MerchantChannelStatus;
import cn.pluss.platform.merchant.MerchantBaseInfoService;
import cn.pluss.platform.merchantChannelStatus.MerchantChannelStatusService;
import cn.pluss.platform.vo.MerchantBaseNewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.UUID;

@Controller
@RequestMapping("merchantBaseInfo")
public class MerchantBaseInfoController extends BaseNoModelController {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private MerchantBaseInfoService mbiService;

    @Autowired
    private MerchantChannelStatusService chsService;

    @GetMapping("/{userId}")
    @ResponseBody
    public Result<Object> detail(@PathVariable("userId") String userId) {
        MerchantBaseInfo mbi = mbiService.getMerchantBaseInfoByUserId(userId);
        return ResultGenerator.genSuccessResult(mbi);
    }

    /**
     * 引导页
     *
     * @return
     */
    @GetMapping("/index")
    public String index() {
        return "merchantBaseInfo/merchantBaseInfoList";
    }
    /**
     * 分页查询
     */
    @GetMapping("/queryMerchantBaseInfoPage")
    @ResponseBody
    public Map<String, Object> listMerchantBaseInfoPage(@RequestParam(defaultValue = "1") Integer currPage, Integer size,
            String column, Boolean asc, MerchantBaseNewVO merchantBaseNewVO) {
        return mbiService.listMerchantBaseInfoPage(currPage, size, column, asc, merchantBaseNewVO);
    }

    @RequestMapping("/updateInfo")
    @ResponseBody
    public Result<Object> updateInfo(MerchantBaseInfo baseInfo) {
        mbiService.updateById(baseInfo);
        return ResultGenerator.genSuccessResult("操作成功",null);
    }

    @RequestMapping("/updateSettleType")
    @ResponseBody
    public Result<Object> updateSettleType(MerchantChannelStatus channel) {
        chsService.updateById(channel);
        return ResultGenerator.genSuccessResult("操作成功",null);
    }

    @RequestMapping("/createKey")
    @ResponseBody
    public Result<Object> createKey() {
        String uuid = UUID.randomUUID().toString().replace("-","");
        return ResultGenerator.genSuccessResult("操作成功",uuid);
    }


}