package com.viettel.campaign.repository.ccms_full.impl;

import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.CampaignCompleteCode;
import com.viettel.campaign.repository.ccms_full.CampaignCompleteCodeRepositoryCustom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Repository
public class CampaignCompleteCompleteCodeRepositoryIpml implements CampaignCompleteCodeRepositoryCustom {

    @Autowired
    @PersistenceContext( unitName= DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL)
    private EntityManager entityManager;

    private Logger log = LoggerFactory.getLogger(CampaignCompleteCompleteCodeRepositoryIpml.class);

    @Override
//    @Transactional(DataSourceQualify.CCMS_FULL)
    public CampaignCompleteCode updateStatusById(Long id) {
        CampaignCompleteCode dto = new CampaignCompleteCode();
        try {
            CampaignCompleteCode e = entityManager.find(CampaignCompleteCode.class, id);
            e.setStatus(new Short("0")); // set status = 0 --> khong hoat dong
            entityManager.merge(e);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return dto;
    }

    @Override
//    @Transactional(DataSourceQualify.CCMS_FULL)
    public CampaignCompleteCode findMaxValueCampaignType(Long companySiteId) {
        CampaignCompleteCode result = new CampaignCompleteCode();
        try {

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return result;
    }
}
