package com.lanyuanxiaoyao.bookstore.service;

import com.lanyuanxiaoyao.bookstore.entity.Book;
import com.lanyuanxiaoyao.bookstore.entity.vo.Option;
import com.lanyuanxiaoyao.bookstore.repository.BookRepository;
import com.lanyuanxiaoyao.service.template.service.SimpleServiceSupport;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class BookService extends SimpleServiceSupport<Book> {
  private final BookRepository bookRepository;

  public BookService(BookRepository repository) {
    super(repository);
    this.bookRepository = repository;
  }

  public List<Option> tags() {
    return bookRepository.findDistinctTags()
        .stream()
        .map(tag -> new Option(tag, tag))
        .toList();
  }
}

