package com.ga.common.system;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class ApiAccessLogService {

    private final SystemLogMapper logMapper;

    @Async("asyncExecutor")
    public void saveAsync(Long userId, String method, String url, String requestParam,
                          String responseCode, int responseTime, String ipAddress, String errorMessage) {
        try {
            logMapper.insertApiAccessLog(userId, method, url, requestParam, responseCode,
                    responseTime, ipAddress, errorMessage);
        } catch (Exception e) {
            log.warn("ApiAccessLog save fail: {}", e.getMessage());
        }
    }
}
