package com.softwarebr.nunu.service.go.impl;

import com.softwarebr.nunu.entity.go.PolicyLabel;
import com.softwarebr.nunu.dao.go.PolicyLabelDao;
import com.softwarebr.nunu.service.go.PolicyLabelService;
import com.brframework.commondb.core.AbstractEntityService;
import com.brframework.commondb.core.CommonRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lilin
 * @date 2020-02-19 16:28:24
 */

@Slf4j
@Service
public class PolicyLabelServiceImpl extends AbstractEntityService<PolicyLabel, Long, Object> implements PolicyLabelService {

    @Autowired
    private PolicyLabelDao policyLabelDao;

    @Override
    public CommonRepository<Long, PolicyLabel> getRepository() {
        return policyLabelDao;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeByPolicyId(Long policyId) {
        policyLabelDao.deleteByPolicyId(policyId);
    }


    @Override
    public List<PolicyLabel> getPolicyLabel(Long policyId) {

        return policyLabelDao.findByPolicyId(policyId);
    }

    @Override
    public List<PolicyLabel> getByLabels(List<Long> secondLabelIds) {

        return policyLabelDao.findPolicyLabelByChildId(secondLabelIds, secondLabelIds.size());
    }


}