import { Injectable } from '@nestjs/common';
import { ReviewItemDto } from './review-item.dto';

export interface Review extends ReviewItemDto {
  id: number;
}

@Injectable()
export class ReviewsService {
  private reviews: Review[] = [
    {
      id: 1,
      reviewerId: 1,
      yachtId: 1,
      starsCount: 5,
      description: 'Excellent yacht!',
    },
    {
      id: 2,
      reviewerId: 2,
      yachtId: 1,
      starsCount: 4,
      description: 'Very good experience',
    },
    {
      id: 3,
      reviewerId: 1,
      yachtId: 3,
      starsCount: 3,
      description: 'Average condition',
    },
    {
      id: 4,
      reviewerId: 2,
      yachtId: 5,
      starsCount: 5,
      description: 'Perfect for sailing',
    },
    {
      id: 5,
      reviewerId: 1,
      yachtId: 7,
      starsCount: 4,
      description: 'Comfortable and fast',
    },
    {
      id: 6,
      reviewerId: 2,
      yachtId: 9,
      starsCount: 2,
      description: 'Needs maintenance',
    },
    {
      id: 7,
      reviewerId: 1,
      yachtId: 11,
      starsCount: 5,
      description: 'Luxury experience',
    },
    {
      id: 8,
      reviewerId: 2,
      yachtId: 12,
      starsCount: 4,
      description: 'Great value for money',
    },
  ];

  private idCounter = 9;

  createReview(dto: ReviewItemDto): Review {
    const review = {
      id: this.idCounter++,
      ...dto,
    };

    this.reviews.push(review);
    return review;
  }

  getReviewsByUserId(userId: number): Review[] {
    return this.reviews.filter((r) => r.reviewerId === userId);
  }

  getReviewsByYachtId(yachtId: number): Review[] {
    return this.reviews.filter((r) => r.yachtId === yachtId);
  }

  getAllReviews(): Review[] {
    return this.reviews;
  }
}
