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

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

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

import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyContract;
import com.ecep.contract.model.Contract;

@Repository
public interface CompanyContractRepository extends
        // JDBC interfaces
        CrudRepository<CompanyContract, Integer>, PagingAndSortingRepository<CompanyContract, Integer>,
        // JPA interfaces
        JpaRepository<CompanyContract, Integer>, JpaSpecificationExecutor<CompanyContract> {

    List<CompanyContract> findByCompanyId(int companyId);

    List<CompanyContract> findByCompany(Company company);

    Stream<CompanyContract> findStreamByCompany(Company company);

    Optional<CompanyContract> findByContractId(int contractId);

    Optional<CompanyContract> findByContract(Contract contract);

    Optional<CompanyContract> findByCompanyAndContract(Company company, Contract contract);

    List<CompanyContract> findAllByCompany(Company company);

    /**
     * Delete all company contracts by company
     *
     * @param company Company
     * @return 删除的记录行数
     */
    int deleteAllByCompany(Company company);
}
