package com.izouma.wenlvju.repo.performance;

import com.izouma.wenlvju.domain.performance.Programme;
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.util.List;

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

    long countAllByPerformanceId(Long performanceId);

    List<Programme> findAllByPerformanceIdAndStatus(Long performanceId, int status);

    long countAllByArrangeIdAndStatusIsNotNull(Long arrangeId);

    @Query("update Programme t set t.allSigned = true where t.arrangeId = ?1")
    @Modifying
    @Transactional
    void allSigned(Long arrangeId);

    @Query("update Programme t set t.score = ?1 where t.id = ?2")
    @Modifying
    @Transactional
    void score(double score, Long id);

//    List<Programme> findAllByArrangeId(Long arrangeId);

//    Programme findFirstByArrangeIdOrderByShowTimeDesc(Long arrangeId);
}