package com.example.demo.repository;

import java.util.Optional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.example.demo.model.NovelComicTask;

@Repository
public interface NovelComicTaskRepository extends JpaRepository<NovelComicTask, Long> {

    Optional<NovelComicTask> findByTaskId(String taskId);

    Optional<NovelComicTask> findByIdAndUsername(Long id, String username);

    Page<NovelComicTask> findByUsernameOrderByCreatedAtDesc(String username, Pageable pageable);

    @Modifying
    @Query("DELETE FROM NovelComicTask t WHERE t.id = :id AND t.username = :username")
    int deleteByIdAndUsername(@Param("id") Long id, @Param("username") String username);
}
