package com.ecep.contract.ds.project.repository;

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

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import com.ecep.contract.model.Contract;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectCost;

@Repository
public interface ProjectCostRepository extends JpaRepository<ProjectCost, Integer>, JpaSpecificationExecutor<ProjectCost> {
    /**
     * 根据合同查询
     *
     * @param contract 合同
     * @return cost
     */
    Optional<ProjectCost> findByContract(Contract contract);

    /**
     * 根据项目查询
     *
     * @param project 项目
     * @return cost
     */
    Optional<ProjectCost> findByProject(Project project);


    List<ProjectCost> findAllByProject(Project project);

    Optional<ProjectCost> findTopOneByProjectAndVersionGreaterThanOrderByVersionDesc(Project project, int version);


    Optional<ProjectCost> findOneByProjectAndVersion(Project project, int version);
}
