package com.tuoheng.controller;

import com.tuoheng.constant.CommonConstant;
import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.dto.OidcTenantDto;
import com.tuoheng.model.param.CreateClientTenantDto;
import com.tuoheng.model.query.TenantQuery;
import com.tuoheng.model.query.UserQuery;
import com.tuoheng.service.ClientUserSevice;
import com.tuoheng.service.CurrentUser;
import com.tuoheng.service.TenantService;
import com.tuoheng.until.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chenjiandong
 * @description: TODO
 * @date 2022/12/7 16:17
 */
@RestController
@RequestMapping("/tenant")
@Slf4j
public class TenantController {

    @Autowired
    private TenantService tenantService;

    @PostMapping("/createTenant")
    public JsonResult createClientTenant(@RequestBody CreateClientTenantDto createClientTenantDto,
                                         @CurrentUser LoginUser loginUser) {
        return tenantService.createClientTenant(createClientTenantDto, loginUser);
    }

    /**
     * 查询租户列表
     *
     * @return
     */
    @GetMapping("/list")
    public JsonResult list(TenantQuery query) {
        return tenantService.findTenants(query);
    }

    /**
     * 根据id查询出租户详情
     *
     * @return
     */
    @GetMapping("/getDetaile")
    public JsonResult getDetaile(TenantQuery query) {
        return tenantService.getDetaile(query);
    }

    /**
     * 查询租户下所有的用户数据
     *
     * @return
     */
    @GetMapping("/findUserList")
    public JsonResult findUserList(UserQuery query) {
        return tenantService.findUserList(query);
    }

    /**
     * 更新业务租户信息及密码接口
     *
     * @param dto
     * @param loginUser
     * @return
     */
    @PostMapping("/edit")
    public JsonResult edit(@RequestBody CreateClientTenantDto dto, @CurrentUser LoginUser loginUser) {
        return tenantService.editTenant(dto, loginUser);

    }

    /**
     * 更新租户状态(1 启用 0禁用)
     *
     * @return
     */
    @PostMapping("/status")
    public JsonResult updateStatus(@RequestBody CreateClientTenantDto dto, @CurrentUser LoginUser loginUser) {
        return tenantService.updateStatus(dto, loginUser);
    }

    /**
     * 重置密码
     * @param dto
     * @param loginUser
     * @return
     */
    @PostMapping("/reset")
    public JsonResult resetPassward(@RequestBody CreateClientTenantDto dto, @CurrentUser LoginUser loginUser) {
        return tenantService.resetPassward(dto, loginUser);
    }


}
