package sgc.portal.cw.cw0632.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.base.websquare.GridRowStatus;
import sgc.portal.cw.cw0632.model.CW06320001U;
import sgc.portal.cw.cw0632.dto.CW06320001USearch;
import sgc.portal.cw.cw0632.persistence.CW06320001UMapper;
import sgc.portal.com.sym.mail.service.MailService;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CW06320001UService {
    private final CW06320001UMapper mapper;
    private final MailService mailService;

    public CW06320001UService(CW06320001UMapper mapper, MailService mailService) {
        this.mapper = mapper;
        this.mailService = mailService;
    }

    public List<EasyHashMap<String, Object>> getList(CW06320001USearch search) {
        return mapper.getList(search);
    }
    
    @Transactional
    public Map<String, String> sendMail(List<CW06320001U> CW06320001U) {
    	
    	Map<String,String> result = new HashMap<>();

        for (CW06320001U cW06320001U : CW06320001U) {
        	
        	//System.out.println("===================mGbn: " + cW06320001U.getMailGbn());
        	//System.out.println("===================statusCd: " + cW06320001U.getStatusCd());
        	
        	StringBuffer sContent = new StringBuffer();
    		
        	String srecvAddress 	= mapper.selectUserEmail(cW06320001U);
    		String cmpnCd = cW06320001U.getCmpnCd();
        	String sSubject 	= mapper.selectEmailTitle(cW06320001U);
    		String ssubSubject = sSubject;
    		String sSender = cW06320001U.getEmpNo();	
    		sContent.append(mapper.selectEmailConts(cW06320001U));

        	//System.out.println("===================srecvAddress: " + srecvAddress);
        	//System.out.println("===================sSubject: " + sSubject);
        	//System.out.println("===================sSender: " + sSender);
        	//System.out.println("===================sContent: " + sContent);
        	
			mailService.mailSend4(cmpnCd, sSubject, ssubSubject, sContent, sSender, srecvAddress);
			
        }
        
        return result;
    }
}
