package cn.novalon.gym.manage.groupcourse.dao;

import cn.novalon.gym.manage.groupcourse.entity.CourseTypeLabelEntity;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface CourseTypeLabelDao extends R2dbcRepository<CourseTypeLabelEntity, Long> {

    Flux<CourseTypeLabelEntity> findByTypeIdAndDeletedAtIsNull(Long typeId);

    Flux<CourseTypeLabelEntity> findByLabelIdAndDeletedAtIsNull(Long labelId);

    Mono<CourseTypeLabelEntity> findByTypeIdAndLabelIdAndDeletedAtIsNull(Long typeId, Long labelId);

    @Modifying
    @Query("UPDATE course_type_label SET deleted_at = :deletedAt WHERE type_id = :typeId AND label_id = :labelId")
    Mono<Integer> deleteByTypeIdAndLabelId(Long typeId, Long labelId, LocalDateTime deletedAt);

    @Modifying
    @Query("UPDATE course_type_label SET deleted_at = :deletedAt WHERE type_id = :typeId")
    Mono<Integer> deleteByTypeId(Long typeId, LocalDateTime deletedAt);

    @Modifying
    @Query("DELETE FROM course_type_label WHERE type_id = :typeId AND label_id = :labelId")
    Mono<Integer> physicalDeleteByTypeIdAndLabelId(Long typeId, Long labelId);

    @Modifying
    @Query("UPDATE course_type_label SET deleted_at = :deletedAt WHERE label_id = :labelId")
    Mono<Integer> deleteByLabelId(Long labelId, LocalDateTime deletedAt);
}