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

import cn.novalon.gym.manage.groupcourse.entity.CourseLabelEntity;
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;

@Repository
public interface CourseLabelDao extends R2dbcRepository<CourseLabelEntity, Long> {

    Mono<CourseLabelEntity> findByIdIsAndDeletedAtIsNull(Long id);

    Flux<CourseLabelEntity> findAllByDeletedAtIsNull();

    Flux<CourseLabelEntity> findByLabelNameContainingAndDeletedAtIsNull(String labelName);

    Mono<CourseLabelEntity> findByLabelNameAndDeletedAtIsNull(String labelName);

    @Modifying
    @Query("UPDATE course_label SET deleted_at = :deletedAt WHERE id = :id")
    Mono<Integer> softDelete(Long id, LocalDateTime deletedAt);
}