import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { PRODUCT_DATA_PROVIDER } from './product-data-provider.token';
import { Product, ProductCategory, ProductListQuery, ProductListResult, ProductSearchQuery, RelatedProductsQuery } from './models/product-domain.model';
import { EngagementListQuery, EngagementListResult, Question, RatingSummary, Review, SubmitQuestionInput, SubmitReviewInput } from './models/product-engagement.model';

@Injectable({ providedIn: 'root' })
export class ProductDataService {
  private readonly provider = inject(PRODUCT_DATA_PROVIDER);

  getProducts(query?: ProductListQuery): Observable<ProductListResult> {
    return this.provider.getProducts(query);
  }

  getProduct(productID: number): Observable<Product> {
    return this.provider.getProduct(productID);
  }

  getCategories(): Observable<ProductCategory[]> {
    return this.provider.getCategories();
  }

  searchProducts(query: ProductSearchQuery): Observable<ProductListResult> {
    return this.provider.searchProducts(query);
  }

  getFeaturedProducts(query?: ProductListQuery): Observable<ProductListResult> {
    return this.provider.getFeaturedProducts(query);
  }

  getLatestProducts(query?: ProductListQuery): Observable<ProductListResult> {
    return this.provider.getLatestProducts(query);
  }

  getProductsByCategory(categoryID: number, query?: ProductListQuery): Observable<ProductListResult> {
    return this.provider.getProductsByCategory(categoryID, query);
  }

  getRelatedProducts(query: RelatedProductsQuery): Observable<ProductListResult> {
    return this.provider.getRelatedProducts(query);
  }

  loadRating(productID: number): Observable<RatingSummary> {
    return this.provider.loadRating(productID);
  }

  loadReviews(productID: number, query?: EngagementListQuery): Observable<EngagementListResult<Review>> {
    return this.provider.loadReviews(productID, query);
  }

  loadQuestions(productID: number, query?: EngagementListQuery): Observable<EngagementListResult<Question>> {
    return this.provider.loadQuestions(productID, query);
  }

  submitReview(productID: number, input: SubmitReviewInput): Observable<void> {
    return this.provider.submitReview(productID, input);
  }

  submitQuestion(productID: number, input: SubmitQuestionInput): Observable<void> {
    return this.provider.submitQuestion(productID, input);
  }
}
