package org.hso.ecommerce.repos.shop;

import org.hso.ecommerce.entities.shop.Article;
import org.hso.ecommerce.entities.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

@Repository
public interface ArticleRepository extends JpaRepository<Article, Long> {

    @Query("SELECT a FROM Article a WHERE a.id = :articleId")
    Article findArticleById(@Param("articleId") long articleId);


    @Query("SELECT a FROM Article a JOIN a.related ao WHERE ao.should_be_advertised = true")
    List<Article> getAdvertisedArticles();


    @Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC")
    List<Article> getOrderedArticles();


}

