import { ApiReviewResponseAttributes } from 'src/application/models/api/responseGenerics';
import { isApiReviewRichInformation } from './isApiReviewRichInformation';

export const isApiReviewResponseAttributes = (obj: unknown): obj is ApiReviewResponseAttributes => {
  if (obj == null || typeof obj !== 'object') {
    return false;
  }

  if ('title' in obj && obj.title != null && typeof obj.title !== 'string') {
    return false;
  }

  if ('review' in obj && typeof obj.review !== 'string') {
    return false;
  }

  if ('reviewer' in obj && typeof obj.reviewer !== 'string') {
    return false;
  }

  if ('stars' in obj && typeof obj.stars !== 'number') {
    return false;
  }

  if ('rich_information' in obj && !isApiReviewRichInformation(obj.rich_information)) {
    return false;
  }

  return true;
};
