package cn.iocoder.yudao.module.system.controller.admin.tenant;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.enterprise.TenantBaseInfoSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantBaseInfoDO;
import cn.iocoder.yudao.module.system.service.tenant.TenantBaseInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 租户基本信息")
@RestController
@RequestMapping("/system/tenantBaseInfo")
@Validated
public class TenantBaseInfoController {

    @Resource
    private TenantBaseInfoService tenantBaseInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建租户基本信息")
    @TenantIgnore
    public CommonResult<Long> createTenantBaseInfo(@Valid @RequestBody TenantBaseInfoSaveReqVO createReqVO) {
        return success(tenantBaseInfoService.createTenantBaseInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新租户基本信息")
    @TenantIgnore
    public CommonResult<Boolean> updateTenantBaseInfo(@Valid @RequestBody TenantBaseInfoSaveReqVO updateReqVO) {
        tenantBaseInfoService.updateTenantBaseInfo(updateReqVO);
        return success(true);
    }
//
//    @DeleteMapping("/delete")
//    @Operation(summary = "删除租户基本信息")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('system:tenant-base-info:delete')")
//    public CommonResult<Boolean> deleteTenantBaseInfo(@RequestParam("id") Long id) {
//        tenantBaseInfoService.deleteTenantBaseInfo(id);
//        return success(true);
//    }
//
    @GetMapping("/get")
    @Operation(summary = "获得租户基本信息")
    @Parameter(name = "tenantId", description = "租户ID", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<TenantBaseInfoDO> getTenantBaseInfo(@RequestParam("tenantId") Long tenantId) {
        return success(tenantBaseInfoService.getTenantBaseInfo(tenantId));
    }
//
//    @GetMapping("/page")
//    @Operation(summary = "获得租户基本信息分页")
//    @PreAuthorize("@ss.hasPermission('system:tenant-base-info:query')")
//    public CommonResult<PageResult<TenantBaseInfoRespVO>> getTenantBaseInfoPage(@Valid TenantBaseInfoPageReqVO pageReqVO) {
//        PageResult<TenantBaseInfoDO> pageResult = tenantBaseInfoService.getTenantBaseInfoPage(pageReqVO);
//        return success(BeanUtils.toBean(pageResult, TenantBaseInfoRespVO.class));
//    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出租户基本信息 Excel")
//    @PreAuthorize("@ss.hasPermission('system:tenant-base-info:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportTenantBaseInfoExcel(@Valid TenantBaseInfoPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<TenantBaseInfoDO> list = tenantBaseInfoService.getTenantBaseInfoPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "租户基本信息.xls", "数据", TenantBaseInfoRespVO.class,
//                        BeanUtils.toBean(list, TenantBaseInfoRespVO.class));
//    }

}