package com.malk.pro.controller;

import com.malk.filter.NoAuth;
import com.malk.pro.tenant.TenantRegistryService;
import com.malk.server.common.McR;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 管理入口（仅 dev profile 启用）
 *
 * <p>仅用于开发期热刷租户注册表。生产 profile 下本 Controller 不装配。</p>
 */
@Profile("dev")
@RestController
@RequestMapping("/_admin")
public class AdminController {

    @Autowired
    private TenantRegistryService registry;

    /** 手动热刷整个注册表 */
    @NoAuth
    @PostMapping("/reloadTenant")
    public McR reloadTenant() {
        registry.loadAll();
        Map<String, Object> data = new HashMap<>();
        data.put("tenants", registry.size());
        return McR.success(data);
    }
}
