package com.ecep.contract.service;

import java.util.List;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import com.ecep.contract.converter.ProjectIndustryStringConverter;
import com.ecep.contract.vm.ProjectIndustryViewModel;
import com.ecep.contract.vo.ProjectIndustryVo;

import javafx.util.StringConverter;

@Service
@CacheConfig(cacheNames = "project-industry")
public class ProjectIndustryService extends QueryService<ProjectIndustryVo, ProjectIndustryViewModel> {
    private final StringConverter<ProjectIndustryVo> stringConverter = new ProjectIndustryStringConverter(this);

    @Cacheable(key = "#p0")
    @Override
    public ProjectIndustryVo findById(Integer id) {
        return super.findById(id);
    }

    public ProjectIndustryVo findByCode(String code) {
        return findOneByProperty("code", code);
    }

    public ProjectIndustryVo findByName(String name) {
        return findOneByProperty("name", name);
    }

    @Cacheable(key = "'all'")
    @Override
    public List<ProjectIndustryVo> findAll() {
        return super.findAll();
    }

    @Caching(evict = { @CacheEvict(key = "#p0.id"), @CacheEvict(key = "'all'") })
    @Override
    public ProjectIndustryVo save(ProjectIndustryVo entity) {
        return super.save(entity);
    }

    @Caching(evict = { @CacheEvict(key = "#p0.id"), @CacheEvict(key = "'all'") })
    @Override
    public void delete(ProjectIndustryVo entity) {
        super.delete(entity);
    }

}
