package com.tuoheng.admin.controller.callback;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.request.third.oidc.CreateOidcTenantRequest;
import com.tuoheng.admin.request.third.oidc.DeletedOidcTenantRequest;
import com.tuoheng.admin.request.third.oidc.EditOidcTenantRequest;
import com.tuoheng.admin.service.third.oidc.OidcService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * oidc平台回调前端控制器
 *
 * @author wanjing
 * @team tuoheng
 * @date 2023-02-23
 */
@Slf4j
@RestController
@RequestMapping("/oidc/callback")
public class OidcCallbackController {

    @Autowired
    private OidcService oidcService;

    /**
     * 创建租户
     */
    @PostMapping("/tenant/create")
    public JsonResult createTenant(@RequestBody CreateOidcTenantRequest request) {
        log.info("被oidc调用，创建租户：{}", JSONObject.toJSONString(request));
        return oidcService.createTenant(request);
    }

    /**
     * 创建用户
     */
    @PostMapping("/tenant/edit")
    public JsonResult editTenant(@RequestBody EditOidcTenantRequest request) {
        log.info("被oidc调用，修改租户：{}", JSONObject.toJSONString(request));
        return oidcService.editTenant(request);
    }

    /**
     * 删除用户
     */
    @PostMapping("/tenant/deleted")
    public JsonResult deletedTenant(@RequestBody DeletedOidcTenantRequest request) {
        log.info("被oidc调用，删除租户：{}", JSONObject.toJSONString(request));
        return oidcService.deletedTenant(request);
    }
    /**
     * 查询所有可用的角色
     *
     * @return
     */
    @GetMapping("/getRoleList")
    public JsonResult getRoleList() {
        return oidcService.getRoleList();
    }

    /**
     * 查询角色对应的菜单
     *
     * @return
     */
    @GetMapping("/getMenuList/{roleId}")
    public JsonResult getMenuList(@PathVariable("roleId") Integer roleId) {
        return oidcService.getMenuList(roleId);
    }

}
