# ----------------------------------------------------------
# LIST ALL (admin/debug)
# ----------------------------------------------------------
query listClientFeedbacks(
  $offset: Int
  $limit: Int
) @auth(level: USER) {
  clientFeedbacks(offset: $offset, limit: $limit) {
    id
    businessId
    vendorId
    rating
    comment
    date
    createdAt

    business { id businessName }
    vendor { id companyName }
  }
}

# ----------------------------------------------------------
# GET BY ID
# ----------------------------------------------------------
query getClientFeedbackById($id: UUID!) @auth(level: USER) {
  clientFeedback(id: $id) {
    id
    businessId
    vendorId
    rating
    comment
    date
    createdAt

    business { id businessName }
    vendor { id companyName }
  }
}

# ----------------------------------------------------------
# LIST BY BUSINESS
# ----------------------------------------------------------
query listClientFeedbacksByBusinessId(
  $businessId: UUID!
  $offset: Int
  $limit: Int
) @auth(level: USER) {
  clientFeedbacks(
    where: { businessId: { eq: $businessId } }
    offset: $offset
    limit: $limit
    orderBy: { date: DESC }
  ) {
    id
    businessId
    vendorId
    rating
    comment
    date
    createdAt

    business { id businessName }
    vendor { id companyName }
  }
}

# ----------------------------------------------------------
# LIST BY VENDOR
# ----------------------------------------------------------
query listClientFeedbacksByVendorId(
  $vendorId: UUID!
  $offset: Int
  $limit: Int
) @auth(level: USER) {
  clientFeedbacks(
    where: { vendorId: { eq: $vendorId } }
    offset: $offset
    limit: $limit
    orderBy: { date: DESC }
  ) {
    id
    businessId
    vendorId
    rating
    comment
    date
    createdAt

    business { id businessName }
    vendor { id companyName }
  }
}

# ----------------------------------------------------------
# LIST BY BUSINESS + VENDOR (pair)
# ----------------------------------------------------------
query listClientFeedbacksByBusinessAndVendor(
  $businessId: UUID!
  $vendorId: UUID!
  $offset: Int
  $limit: Int
) @auth(level: USER) {
  clientFeedbacks(
    where: {
      businessId: { eq: $businessId }
      vendorId: { eq: $vendorId }
    }
    offset: $offset
    limit: $limit
    orderBy: { date: DESC }
  ) {
    id
    businessId
    vendorId
    rating
    comment
    date
    createdAt

    business { id businessName }
    vendor { id companyName }
  }
}

# ----------------------------------------------------------
# FILTER (rating + date range)
# NOTE: using Timestamp ops: ge/le
# ----------------------------------------------------------
query filterClientFeedbacks(
  $businessId: UUID
  $vendorId: UUID
  $ratingMin: Int
  $ratingMax: Int
  $dateFrom: Timestamp
  $dateTo: Timestamp
  $offset: Int
  $limit: Int
) @auth(level: USER) {
  clientFeedbacks(
    where: {
      businessId: { eq: $businessId }
      vendorId: { eq: $vendorId }
      rating: { ge: $ratingMin, le: $ratingMax }
      date: { ge: $dateFrom, le: $dateTo }
    }
    offset: $offset
    limit: $limit
    orderBy: { date: DESC }
  ) {
    id
    businessId
    vendorId
    rating
    comment
    date

    business { id businessName }
    vendor { id companyName }
  }
}

# ----------------------------------------------------------
# QUICK KPI: average rating for a vendor (client-side aggregate)
# You fetch rows; Flutter/web computes avg.
# ----------------------------------------------------------
query listClientFeedbackRatingsByVendorId(
  $vendorId: UUID!
  $dateFrom: Timestamp
  $dateTo: Timestamp
) @auth(level: USER) {
  clientFeedbacks(
    where: {
      vendorId: { eq: $vendorId }
      date: { ge: $dateFrom, le: $dateTo }
    }
    orderBy: { date: DESC }
  ) {
    id
    rating
    comment
    date
    business { id businessName }
    vendor { id companyName }
  }
}
