package com.cico.nest.lcdp.boot.core.system.api.tenant;

import com.cico.nest.lcdp.boot.core.system.service.tenant.TenantService;
import com.cico.nest.lcdp.boot.tenant.core.context.TenantContextHolder;
import com.cico.nest.lcdp.boot.tenant.core.util.TenantUtils;
import com.cico.nest.lcdp.framework.api.tenant.LcdpTenantApi;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 多租户的 API 实现类
 *
 * @author zws
 */
@Service
public class LcdpTenantApiImpl implements LcdpTenantApi {

    @Resource
    private TenantService tenantService;

    @Override
    public List<Long> getTenantIdList() {
        return tenantService.getTenantIdList();
    }

    @Override
    public void validateTenant(Long id) {
        tenantService.validTenant(id);
    }

    @Override
    public void execute(Long tenantId, Runnable runnable) {
        TenantUtils.execute(tenantId,runnable);
    }

    @Override
    public Long getCurrentTenantId() {
        return TenantContextHolder.getTenantId();
    }

}
