package com.izouma.wenlvju.repo;

import com.izouma.wenlvju.domain.TrainingInstitution;
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 TrainingInstitutionRepo extends JpaRepository<TrainingInstitution, Long>, JpaSpecificationExecutor<TrainingInstitution> {
    @Query("update TrainingInstitution t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);

    @Query(nativeQuery = true, value = "select DISTINCT phone from training_institution where submit = false and phone REGEXP '^[1][356789][0-9]{9}$'")
    List<String> findAllBySubmitFalseAndPhoneIsNotNull();

    @Query(nativeQuery = true, value = "select DISTINCT phone from training_institution where submit = false and phone REGEXP '^[1][356789][0-9]{9}$' limit 2000,2000")
    List<String> findAllBySubmitFalseAndPhoneIsNotNullLimit();

    List<TrainingInstitution> findAllByPhoneIsNull();

    @Query(nativeQuery = true, value = "select name from training_institution where name like ?1 limit ?2,?3")
    List<String> findAllByNameLike(String name, int page, int size);

    TrainingInstitution findByUscc(String uscc);
}