package com.yonge.cooleshow.website.controller.open;

import com.alibaba.fastjson.JSONObject;
import com.microsvc.toolkit.common.response.template.R;
import com.yonge.cooleshow.biz.dal.service.CooperateTenantService;
import com.yonge.cooleshow.biz.dal.service.SmsCodeService;
import com.yonge.cooleshow.biz.dal.wrapper.CooperateTenantWrapper;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.toolset.base.exception.BizException;
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;

@Slf4j
@Validated
@RestController
@RequestMapping("${app-config.url.website:}/open/cooperateTenant")
@Api(tags = "合作机构")
public class OpenCooperateTenantController extends BaseController {

    @Autowired
    private CooperateTenantService cooperateTenantService;

    @Autowired
    private SmsCodeService smsCodeService;

    @ApiOperation(value = "新增", notes = "合作机构- 传入 CooperateTenantWrapper.CooperateTenant")
    @PostMapping("/save")
    public R<JSONObject> add(@Validated @RequestBody CooperateTenantWrapper.CooperateTenant cooperateTenant) {
        boolean validCode = smsCodeService.verifyValidCode(cooperateTenant.getPhone(), cooperateTenant.getCode(), "");
        if (!validCode) {
            throw new BizException("验证码错误");
        }
        // 新增数据
        cooperateTenantService.add(cooperateTenant);
        return R.defaultR();
    }

}