package com.izouma.zhirongip.repo;

import com.izouma.zhirongip.domain.Institution;
import com.izouma.zhirongip.enums.ApplyStatus;
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;

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

    @Query("update Institution t set t.del = true where t.userId = ?1")
    @Modifying
    @Transactional
    void softDeleteByUserId(Long userId);

    Institution findByUserId(Long userId);

    long countAllByStatus(ApplyStatus status);
}