package ru.soune.nocopy.repository;

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.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import ru.soune.nocopy.entity.complaint.ComplaintEntity;
import ru.soune.nocopy.entity.complaint.ComplaintStatus;

import java.util.List;
import java.util.Optional;

@Repository
public interface ComplaintEntityRepository extends JpaRepository<ComplaintEntity, String> {
    Optional<ComplaintEntity> findById(Long id);
    Page<ComplaintEntity> findAll(Pageable pageable);
    Page<ComplaintEntity> findByStatus(ComplaintStatus status, Pageable pageable);
    List<ComplaintEntity> findByViolationId(Long violationId);
    boolean existsByViolationId(Long violationId);

    @Modifying
    @Transactional
    @Query("UPDATE ComplaintEntity c SET c.status = :status WHERE c.id = :id")
    int updateStatus(Long id, ComplaintStatus status);
}
