package com.cico.nest.lcdp.boot.core.infra.api.logger;

import com.cico.nest.lcdp.boot.api.infra.logger.ApiAccessLogApi;
import com.cico.nest.lcdp.boot.api.infra.logger.dto.ApiAccessLogCreateReqDTO;
import com.cico.nest.lcdp.boot.core.infra.dal.dataobject.config.ConfigDO;
import com.cico.nest.lcdp.boot.core.infra.service.config.ConfigService;
import com.cico.nest.lcdp.boot.core.infra.service.logger.ApiAccessLogService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;


/**
 * API 访问日志的 API 实现类
 *
 * @author zws
 */
@Service
@Validated
public class ApiAccessLogApiImpl implements ApiAccessLogApi {

    @Resource
    private ApiAccessLogService apiAccessLogService;
    @Resource
    private ConfigService configService;

    @Override
    public void createApiAccessLog(ApiAccessLogCreateReqDTO createDTO) {
        apiAccessLogService.createApiAccessLog(createDTO);
    }

    @Override
    public boolean isEnable() {
        ConfigDO configDO = configService.getConfigCacheByKey("api-access-log.enable");
        return "true".equals(configDO.getValue());
    }

}
