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 MailAccountFileService extends BaseService {

    private static final String NS = "mailAccountFile.";

    private final CommonService commonService;

    public Map<String, Object> getMailAccountFileList(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        commonService.applyPagination(params);
        int totalCount = sqlSession.selectOne(NS + "getMailAccountFileListCnt", params);
        List<Map<String, Object>> list = sqlSession.selectList(NS + "getMailAccountFileList", params);
        return commonService.buildListResponse(list, totalCount, params);
    }

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

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

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

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