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

import cn.novalon.gym.manage.groupcourse.entity.GroupCourseTypeEntity;
import org.springframework.data.domain.Sort;
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 GroupCourseTypeDao extends R2dbcRepository<GroupCourseTypeEntity, Long> {

    Mono<GroupCourseTypeEntity> findByIdIsAndDeletedAtIsNull(Long id);

    Flux<GroupCourseTypeEntity> findAllByDeletedAtIsNull();

    Flux<GroupCourseTypeEntity> findAllByDeletedAtIsNull(Sort sort);

    Flux<GroupCourseTypeEntity> findByTypeNameContainingAndDeletedAtIsNull(String typeName);

    Flux<GroupCourseTypeEntity> findByCategoryAndDeletedAtIsNull(String category);

    Mono<GroupCourseTypeEntity> findByTypeNameAndDeletedAtIsNull(String typeName);

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