/**
 * Copyright (c) 2022 雷掣 All rights reserved.
 *
 * https://www.lc_crm.com
 *
 * 版权所有，侵权必究！
 */

package io.renren.controller;

import io.renren.common.exception.ErrorCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
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 io.renren.common.utils.Result;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.DefaultGroup;
import io.renren.dto.CustomersDTO;
import io.renren.service.CustomersService;
import io.renren.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("api/customer")
@Api(tags="客户表")
public class CustomerController{
	
	@Autowired
    private CustomersService customersService;
	
	@Autowired
    private UserService userService;
	
	@PostMapping("save")
	@ApiOperation(value = "保存")
	public Result<String> save(@RequestBody CustomersDTO dto) throws Exception {
		ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
        return customersService.inserCustomer(dto);
	}

	@PostMapping("update")
	@ApiOperation(value = "更新")
	public Result<String> update(@RequestBody CustomersDTO dto) throws Exception {
		ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
		return customersService.updateCustomer(dto);
	}
	
	@PostMapping("sendSms")
    @ApiOperation("发送手机验证码")
    public Result<String> getverificationCode(String mobile){
		Boolean flag = userService.getverificationCode(mobile);
		if(flag) {
			return new Result<String>().pageOk(ErrorCode.SUCCESS_CODE,"发送短信成功");
		}
		return new Result<String>().error(ErrorCode.SEND_CODE_ERROR,"发送短信失败");
    }
}