package com.erp.service;

import com.erp.common.BaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;

@Service
@RequiredArgsConstructor
@Slf4j
public class BatchExecutionLogService extends BaseService {

    private final CommonService commonService;

    private static final String NS = "batchExecutionLog.";

    public Map<String, Object> getBatchExecutionLogList(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        commonService.applyPagination(params);
        Integer totalObj = sqlSession.selectOne(NS + "getBatchExecutionLogListCnt", params);
        int totalCount = totalObj != null ? totalObj : 0;
        List<Map<String, Object>> list = sqlSession.selectList(NS + "getBatchExecutionLogList", params);
        return commonService.buildListResponse(list, totalCount, params);
    }

    public Map<String, Object> getBatchExecutionLogInfo(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        return sqlSession.selectOne(NS + "getBatchExecutionLogInfo", params);
    }

    @Transactional
    public Map<String, Object> insertBatchExecutionLog(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        sqlSession.insert(NS + "insertBatchExecutionLog", params);
        return params;
    }

    @Transactional
    public Map<String, Object> updateBatchExecutionLog(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        sqlSession.update(NS + "updateBatchExecutionLog", params);
        return params;
    }

    @Transactional
    public Map<String, Object> deleteBatchExecutionLog(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        sqlSession.delete(NS + "deleteBatchExecutionLog", params);
        return params;
    }

    public Map<String, Object> getBatchExecutionLogLatest(Map<String, Object> params) {
        return sqlSession.selectOne(NS + "getBatchExecutionLogLatest", params);
    }

    public Map<String, Object> getBatchExecutionLogStats(Map<String, Object> params) {
        return sqlSession.selectOne(NS + "getBatchExecutionLogStats", params);
    }
}
