package com.erp.ai.service;

import com.erp.ai.mapper.AiAnalysisLogMapper;
import com.erp.ai.model.AiAnalysisLog;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * AI 분석 이력 서비스.
 * vexplor aiAnalysisLogService.ts 1:1 포팅 (역공학된 인터페이스).
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AiAnalysisLogService {

    private final AiAnalysisLogMapper analysisLogMapper;

    public void save(AiAnalysisLog log) {
        if (log.getExecution_type() == null) log.setExecution_type("manual");
        analysisLogMapper.insert(log);
    }

    public List<AiAnalysisLog> getRecentLogs(long groupId, int days, int limit) {
        return analysisLogMapper.getRecentLogs(groupId, days, limit);
    }

    public BigDecimal getAverageAccuracy(long groupId) {
        BigDecimal v = analysisLogMapper.getAverageAccuracy(groupId);
        return v != null ? v : BigDecimal.ZERO;
    }
}
