package com.starry.admin.modules.system.controller;

import com.starry.admin.modules.system.module.entity.SysTenantEntity;
import com.starry.admin.modules.system.service.ISysTenantService;
import com.starry.admin.utils.SmsUtils;
import com.starry.common.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 动态接口
 *
 * @author admin
 * @since 2024/5/20 下午11:19
 **/
@Api(tags = "短信管理", description = "系统短信发送相关接口")
@Slf4j
@RestController
@RequestMapping("/system/sms")
public class SysSmsController {
    @Resource
    private SmsUtils smsUtils;
    @Resource
    private ISysTenantService tenantService;

    @ApiOperation(value = "发送短信", notes = "向指定手机号发送短信验证码")
    @ApiImplicitParam(name = "phone", value = "手机号码", required = true, dataType = "String", paramType = "query")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @GetMapping("/send")
    public R sendSms(@RequestParam("phone") String phone) {
        smsUtils.sendSmsApi(phone);
        return R.ok();
    }

    @ApiOperation(value = "测试接口", notes = "测试租户角色初始化")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = Boolean.class)})
    @GetMapping("/test")
    public R test() {
        SysTenantEntity sysTenantEntity = tenantService.selectSysTenantByTenantId("y5PNjqco");
        tenantService.initRole(sysTenantEntity);
        return R.ok(true);
    }

}
