package com.ecep.contract.service;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.ProjectFundPlanViewModel;
import com.ecep.contract.vo.ProjectFundPlanVo;
import com.ecep.contract.vo.ProjectVo;

@Service
public class ProjectFundPlanService extends QueryService<ProjectFundPlanVo, ProjectFundPlanViewModel> {

    public List<ProjectFundPlanVo> findAllByProject(ProjectVo project) {
        return findAllByProject(project.getId());
    }

    public List<ProjectFundPlanVo> findAllByProject(Integer projectId) {
        return findAll(ParamUtils.builder()
                .equals("project", projectId)
                .build(), Pageable.unpaged()).getContent();
    }

    public ProjectFundPlanVo newInstanceByProject(Integer projectId) {
        ProjectFundPlanVo vo = new ProjectFundPlanVo();
        vo.setProjectId(projectId);
        return vo;
    }

    public ProjectFundPlanVo newInstanceByProject(ProjectVo project) {
        ProjectFundPlanVo vo = new ProjectFundPlanVo();
        vo.setProjectId(project.getId());
        return vo;
    }

    @Override
    public ProjectFundPlanViewModel createNewViewModel() {
        ProjectFundPlanViewModel model = new ProjectFundPlanViewModel();
        model.getUpdateDate().set(LocalDateTime.now());
        return model;
    }
}
