package cn.com.qmth.examcloud.core.questions.dao;

import java.util.List;

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 cn.com.qmth.examcloud.core.questions.dao.entity.ExportTemplateEntity;

public interface ExportTemplateRepo
        extends JpaRepository<ExportTemplateEntity, Long>, JpaSpecificationExecutor<ExportTemplateEntity> {

    ExportTemplateEntity findByIdAndRootOrgId(Long id, Long rootOrgId);

    List<ExportTemplateEntity> findByRootOrgIdAndType(Long rootOrgId, String type);

    List<ExportTemplateEntity> findByRootOrgIdAndTypeAndEnable(Long rootOrgId, String type, Boolean enable);

    @Query(value = "delete from ec_q_export_template where root_org_id =?1 and id =?2", nativeQuery = true)
    @Modifying
    void deleteByRootOrgIdAndId(Long rootOrgId, Long id);

    @Query(value = "update ec_q_export_template set enable=?3 where root_org_id =?1 and type =?2", nativeQuery = true)
    @Modifying
    void updateEnableByType(Long rootOrgId, String type, Boolean enable);

    @Query(value = "update ec_q_export_template set enable=?3 where root_org_id =?1 and id =?2", nativeQuery = true)
    @Modifying
    void updateEnableById(Long rootOrgId, Long id, Boolean enable);
}
