package com.ecep.contract.service;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.ProjectTypeViewModel;
import com.ecep.contract.vo.ProjectTypeVo;

@Service
@CacheConfig(cacheNames = "project-type")
public class ProjectTypeService extends QueryService<ProjectTypeVo, ProjectTypeViewModel> {

    public ProjectTypeVo findByName(String name) {
        Page<ProjectTypeVo> page = findAll(ParamUtils.builder().equals("name", name).build(), Pageable.ofSize(1));
        if (page.isEmpty()) {
            return null;
        }
        return page.getContent().getFirst();
    }

    public ProjectTypeVo findByCode(String code) {
        Page<ProjectTypeVo> page = findAll(ParamUtils.builder().equals("code", code).build(), Pageable.ofSize(1));
        if (page.isEmpty()) {
            return null;
        }
        return page.getContent().getFirst();
    }

}
