
package com.jeelowcode.core.framework.controller;

import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
import com.jeelowcode.framework.utils.model.JeeLowCodeDept;
import com.jeelowcode.framework.utils.model.JeeLowCodeRole;
import com.jeelowcode.framework.utils.model.JeeLowCodeUser;
import com.jeelowcode.framework.utils.model.JeeLowTenant;
import com.jeelowcode.framework.utils.params.JeeLowCodeDeptParam;
import com.jeelowcode.framework.utils.params.JeeLowCodeUserParam;
import com.jeelowcode.framework.utils.model.global.BaseWebResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "低代码框架-芋道框架接口")
@RestController
@AllArgsConstructor
@RequestMapping(JeeLowCodeBaseConstant.REQUEST_URL_START + "/adapter")
public class AdapterController extends BaseController {

    private final IJeeLowCodeAdapter jeeLowCodeAdapter;

    @GetMapping("/tenant/list")
    @ApiOperationSupport(order = 1)
    @Operation(tags = "芋道适配器",summary = "获取租户列表")
    public BaseWebResult tenantList() {
        List<JeeLowTenant> tenantList = jeeLowCodeAdapter.getTenantList();
        return BaseWebResult.success(tenantList);
    }

    @GetMapping("/dept/list")
    @ApiOperationSupport(order = 1)
    @Operation(tags = "芋道适配器",summary = "获取部门列表")
    public BaseWebResult deptList(JeeLowCodeDeptParam param) {
        List<JeeLowCodeDept> deptList = jeeLowCodeAdapter.getDeptList(param);
        return BaseWebResult.success(deptList);
    }

    @GetMapping("/role/list")
    @ApiOperationSupport(order = 2)
    @Operation(tags = "芋道适配器",summary = "获取角色列表")
    public BaseWebResult roleList() {
        List<JeeLowCodeRole> roleList = jeeLowCodeAdapter.getRoleList();
        return BaseWebResult.success(roleList);
    }

    @PostMapping("/user/list")
    @ApiOperationSupport(order = 3)
    @Operation(tags = "芋道适配器",summary = "获取用户列表")
    public BaseWebResult userList(@RequestBody JeeLowCodeUserParam param) {
        IPage<JeeLowCodeUser> userPage =(IPage<JeeLowCodeUser>) jeeLowCodeAdapter.getUserPage(param.getPageNo(), param.getPageSize(), param);
        return BaseWebResult.success(userPage);
    }
}
