package com.crm.web.service.impl;

import com.crm.rely.backend.core.exception.ServiceException;
import com.crm.rely.backend.model.entity.web.custom.analysis.interaction.history.WebCustomAnalysisInteractionHistoryAddEntity;
import com.crm.rely.backend.model.pojo.table.WebCustomAnalysisInteractionHistoryTable;
import com.crm.web.dao.repository.WebCustomAnalysisInteractionHistoryRepository;
import com.crm.web.service.WebCustomAnalysisInteractionHistoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class WebCustomAnalysisInteractionHistoryServiceImpl implements WebCustomAnalysisInteractionHistoryService {

    @Autowired
    private WebCustomAnalysisInteractionHistoryRepository repository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(WebCustomAnalysisInteractionHistoryAddEntity entity) throws ServiceException {

        WebCustomAnalysisInteractionHistoryTable table = new WebCustomAnalysisInteractionHistoryTable();
        BeanUtils.copyProperties(entity, table);
        repository.save(table);
    }

    @Override
    public boolean existInteraction(Long analysisId, Long customId) throws ServiceException {

        return repository.existsByCustomIdAndAnalysisId(customId, analysisId);
    }


}
