package com.qiaoba.module.tenant.controller;

import com.qiaoba.common.base.result.AjaxResult;
import com.qiaoba.module.tenant.entity.vo.TenantInitCheckVo;
import com.qiaoba.module.tenant.entity.vo.TenantInitVo;
import com.qiaoba.module.tenant.service.SysTenantInitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 租户初始化 Web层
 *
 * @author ailanyin
 * @version 1.0
 * @since 2023/6/27 9:03
 */
@RestController
@RequestMapping("/tenant/init")
@RequiredArgsConstructor
@Tag(name = "租户初始化管理")
public class SysTenantInitController {

    private final SysTenantInitService sysTenantInitService;

    @PostMapping(value = "/check/{tenantId}")
    @Operation(summary = "步骤一: 检查各项参数")
    public TenantInitCheckVo check(@PathVariable String tenantId) {
        return sysTenantInitService.check(tenantId);
    }

    @PostMapping(value = "/createTables/{tenantId}")
    @Operation(summary = "步骤二: 创建数据库表")
    public TenantInitVo createTables(@PathVariable String tenantId) {
        return sysTenantInitService.createTables(tenantId);
    }

    @PostMapping(value = "/initData/{tenantId}")
    @Operation(summary = "步骤三: 导入数据")
    public TenantInitVo initData(@PathVariable String tenantId) throws Exception {
        return sysTenantInitService.initData(tenantId);
    }
    @PostMapping(value = "/initCompleted/{tenantId}")
    @Operation(summary = "初始化完毕")
    public AjaxResult initCompleted(@PathVariable String tenantId) {
        sysTenantInitService.initCompleted(tenantId);
        return AjaxResult.success();
    }
}
