package pwc.taxtech.atms.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.constant.enums.StdAccountEnum;
import pwc.taxtech.atms.entity.StandardAccount;
import pwc.taxtech.atms.entity.StandardAccountExample;

import java.util.List;
import java.util.Optional;

@Service
public class StandardAccountDao {
    @Autowired
    private StandardAccountMapper standardAccountMapper;

    public Optional<List<StandardAccount>> getByIndustryId(String industryId) {
        StandardAccountExample example = new StandardAccountExample();
        StandardAccountExample.Criteria criteria = example.createCriteria();
        criteria.andIndustryIdEqualTo(industryId);
        return Optional.ofNullable(standardAccountMapper.selectByExample(example));
    }

    public List<StandardAccount> getByCodeAndIndustryId(String code, String industryId) {
        StandardAccountExample example = new StandardAccountExample();
        StandardAccountExample.Criteria criteria = example.createCriteria();
        criteria.andCodeEqualTo(code);
        criteria.andIndustryIdEqualTo(industryId);
        return standardAccountMapper.selectByExample(example);
    }

    public List<StandardAccount> getStdAccount(StdAccountEnum.RuleType ruleType, String industryId,Boolean isActive,Boolean isLeaf) {
        StandardAccountExample example = new StandardAccountExample();
        StandardAccountExample.Criteria criteria = example.createCriteria();
        criteria.andRuleTypeEqualTo(ruleType.getCode());
        criteria.andIndustryIdEqualTo(industryId);
        criteria.andIsActiveEqualTo(isActive);
        criteria.andIsLeafEqualTo(isLeaf);
        return standardAccountMapper.selectByExample(example);
    }

}