package com.izouma.zhirongip.repo;

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

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

    Personal findByUserId(Long userId);

    long countAllByStatus(ApplyStatus status);
}