package com.codenetworkz.blog.repositories;

import com.codenetworkz.blog.models.Status;
import com.codenetworkz.blog.models.Tag;

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.Query;
import org.springframework.stereotype.Repository;

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

@Repository
public interface TagRepository extends JpaRepository<Tag, Long> {

    @Query(value ="select t from  Tag t where t.isDelete =:status" )
    List<Tag> findAllAndIsDelete(Status status);

    @Query(value ="select t from  Tag t where t.slug=:slug and t.isDelete =:status" )
    Optional<Tag> findBySlugAndIsDelete(String slug, Status status);

    List<Tag> findAllByIdInAndIsDelete(List<Long> tagIds, Status status);

    @Query(value ="select t from  Tag t where t.slug=:slug and t.isDelete =:status and t.isApproved=:status1" )
    Optional<Tag> findBySlugAndIsDeleteAndIsApproved(String slug, Status status, Status status1);


    Page<Tag> findAllByIsDelete(Status status, Pageable pageable);
}
