package com.tuoheng.controller;

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.service.ClientUserSevice;
import com.tuoheng.service.CurrentUser;
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 ClientUserSevice clientUserSevice;

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

    /**
     * 新增业务平台的租户基本数据
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody OidcTenantDto dto,@CurrentUser LoginUser loginUser){
        return clientUserSevice.addTenant(dto,loginUser);
    }

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

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

    }

    /**
     * 删除租户(逻辑删除)
     * @return
     */
    @PostMapping ("/delete")
    public JsonResult delete(@RequestBody OidcTenantDto dto,@CurrentUser LoginUser loginUser){
        return clientUserSevice.deleteTenant(dto,loginUser);
    }

}
