package com.izouma.wenlvju.repo.performance;

import com.izouma.wenlvju.domain.performance.ArrangeJudge;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.Collection;
import java.util.List;

public interface ArrangeJudgeRepo extends JpaRepository<ArrangeJudge, Long>, JpaSpecificationExecutor<ArrangeJudge> {
    @Query("update ArrangeJudge t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);

    List<ArrangeJudge> findAllByDateAndMorning(LocalDate date, boolean morning);

    @Query("select distinct expertId from ArrangeJudge where date = ?1 and morning = ?2")
    List<Long> findExpertByDateAndMorning(LocalDate date, boolean morning);

    @Query("update ArrangeJudge t set t.del = true where t.arrangeId in ?1")
    @Modifying
    @Transactional
    void cancelJudge(Collection<Long> arrangeIds);

    @Query("select arrangeId from ArrangeJudge where expertId = ?1")
    List<Long> findArrangeIdByExpertId(Long expertId);
}