package com.yn.bftl.thirdparty.common.repository;

import com.yn.bftl.common.common.entity.Sequence;
import com.yn.bftl.common.common.entity.SequenceVersion;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;

@Repository
public interface SequenceVersionRepository extends JpaRepository<SequenceVersion, Long> {

	@Query("From SequenceVersion self where self.sequence = ?1 AND self.startDate <= ?2 AND (self.endDate IS NULL OR self.endDate >= ?2)")
    SequenceVersion findByDate(Sequence sequence, LocalDate date);

	@Query("From SequenceVersion self where self.sequence = ?1 AND MONTH(self.startDate) = ?2 AND YEAR(self.startDate) = ?3")
	public SequenceVersion findByMonth(Sequence sequence, int month, int year);

	@Query("From SequenceVersion self where self.sequence = ?1 AND YEAR(self.startDate) = ?2")
	public SequenceVersion findByYear(Sequence sequence, int year);
}

