package com.sn.sowsysrestapi.domain.repository;

import com.sn.sowsysrestapi.domain.entity.Report;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

@Repository
public interface ReportRepo extends JpaRepository<Report, Long> {

    @Query("select r from Report r " +
            "where r.reportDirectory.id = :reportDirectoryId and r.startDate = :startDate and r.endDate = :endDate")
   List<Report> findByReportDirectoryAndStartDateAndEndDate(Long reportDirectoryId, LocalDate startDate, LocalDate endDate);

    @Query("select r from Report r where r.startDate >= :startDate and r.endDate <= :endDate")
    List<Report> findByStartDateAndEndDate(LocalDate startDate, LocalDate endDate);

    List<Report> findByReportDirectoryId(Long reportDirectoryId);

    List<Report> findByReportDirectoryId(String userCode);

    @Query("select rd.id from ReportDirectory rd where rd.ownerCode = :ownerCode")
    Long getReportDirectoryId(String ownerCode);

    Optional<List<Report>> findPageableByReportDirectoryId(Long reportDirectoryId, Pageable page);

    Optional<Report> findById(Long reportId);


}
