package com.qqchen.deploy.backend.system.api;

import com.qqchen.deploy.backend.system.entity.Tenant;
import com.qqchen.deploy.backend.framework.api.Response;
import com.qqchen.deploy.backend.framework.controller.BaseController;
import com.qqchen.deploy.backend.system.model.TenantDTO;
import com.qqchen.deploy.backend.system.model.query.TenantQuery;
import com.qqchen.deploy.backend.system.service.ITenantService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 租户管理API控制器
 * 提供租户的REST接口，包括：
 * 1. 基础CRUD操作
 * 2. 状态管理
 *
 * @author QQChen
 * @version 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/tenant")
@Tag(name = "租户管理API", description = "对外提供的租户管理接口")
public class TenantApiController extends BaseController<Tenant, TenantDTO, Long, TenantQuery> {

    @Resource
    private ITenantService tenantService;

    @Operation(summary = "获取状态")
    @GetMapping("/{id}/enabled")
    public Response<Boolean> getStatus(
        @Parameter(description = "租户ID", required = true) @PathVariable Long id
    ) {
        return Response.success(tenantService.getStatus(id));
    }

    @Operation(summary = "更新状态")
    @PutMapping("/{id}/enabled")
    public Response<Void> updateStatus(
        @Parameter(description = "租户ID", required = true) @PathVariable Long id,
        @Parameter(description = "是否启用", required = true) @RequestParam boolean enabled
    ) {
        tenantService.updateStatus(id, enabled);
        return Response.success();
    }

    @Override
    protected void exportData(HttpServletResponse response, List<TenantDTO> data) {
        // TODO: 实现导出功能
    }
}