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

import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.CampaignCfg;
import com.viettel.campaign.repository.ccms_full.CampaignCfgRepositoryCustom;
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 CampaignCfgRepositoryIpml implements CampaignCfgRepositoryCustom {

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

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

    @Override
//    @Transactional(DataSourceQualify.CCMS_FULL)
    public CampaignCfg updateStatusById(Long id) {
        CampaignCfg dto = new CampaignCfg();
        try {
            CampaignCfg e = entityManager.find(CampaignCfg.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 CampaignCfg findMaxValueCampaignType(Long companySiteId) {
        CampaignCfg result = new CampaignCfg();
        try {

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

        return result;
    }
}
