# Product Catalog Query Examples
# Demonstrates LTREE operations for product categorization

# Get all products
query GetAllProducts {
  products {
    id
    name
    price
    categoryPath
    sku
  }
}

# Browse electronics category
query BrowseElectronics {
  products(where: {
    categoryPath: { descendantOf: "electronics" }
  }) {
    id
    name
    price
    categoryPath
    categoryDepth
    categoryName
  }
}

# Get products in specific subcategory
query GetLaptops {
  products(where: {
    categoryPath: {
      descendantOf: "electronics.computers.laptops"
      nlevelEq: 4  # electronics.computers.laptops + 1
    }
  }) {
    id
    name
    price
    categoryPath
  }
}

# Find products by category pattern
query GetAppleProducts {
  products(where: {
    categoryPath: { matchesLquery: "electronics.*.apple" }
  }) {
    id
    name
    price
    categoryPath
  }
}

# Price range within category
query GetAffordableLaptops {
  productsInPriceRange(
    minPrice: 1000
    maxPrice: 2000
    category: "electronics.computers.laptops"
  ) {
    id
    name
    price
    categoryPath
  }
}

# Products at specific category depth
query GetTopLevelCategories {
  products(where: {
    categoryPath: { nlevelEq: 2 }
  }) {
    id
    name
    categoryPath
    categoryName
  }
}

# Search with category filter
query SearchElectronics {
  searchProducts(
    query: "wireless"
    category: "electronics"
  ) {
    id
    name
    price
    categoryPath
  }
}

# Get product with related items
query GetProductDetails($id: Int!) {
  product(id: $id) {
    id
    name
    description
    price
    categoryPath
    sku
    categoryDepth
    parentCategory
    relatedProducts {
      id
      name
      price
    }
    siblingProducts {
      id
      name
      price
    }
  }
}

# Category tree view
query GetCategoryTree {
  categoryTree(rootCategory: "electronics") {
    id
    name
    categoryPath
    categoryDepth
  }
}

# Complex filtering: affordable audio equipment
query GetAudioDeals {
  products(where: {
    categoryPath: {
      descendantOf: "electronics.audio"
      nlevelGte: 3
    }
    price: { lte: 500 }
    inStock: { eq: true }
  }) {
    id
    name
    price
    categoryPath
  }
}

# Books by programming topic
query GetProgrammingBooks {
  products(where: {
    categoryPath: {
      descendantOf: "books.technical.programming"
      matchesLquery: "*.programming.*"
    }
  }) {
    id
    name
    price
    categoryPath
  }
}

# Sports equipment by activity
query GetRunningGear {
  products(where: {
    categoryPath: {
      descendantOf: "sports"
      matchesLquery: "*.running.*"
    }
  }) {
    id
    name
    price
    categoryPath
  }
}

# Home appliances on sale
query GetApplianceDeals {
  products(where: {
    categoryPath: {
      descendantOf: "home.kitchen.appliances"
    }
    price: { lte: 300 }
  }) {
    id
    name
    description
    price
    categoryPath
  }
}

# Mutation examples
mutation AddNewProduct {
  addProduct(
    name: "Logitech MX Master 3S"
    description: "Advanced wireless mouse for productivity"
    price: 99.99
    categoryPath: "electronics.computers.accessories.logitech"
    sku: "MX-MASTER-3S"
  ) {
    id
    name
    price
    categoryPath
    sku
  }
}

mutation UpdateProductPrice {
  updatePrice(
    productId: 1
    newPrice: 2299.99
  ) {
    id
    name
    price
    updatedAt
  }
}

mutation MoveProductsToNewCategory {
  bulkUpdateCategory(
    oldCategoryPath: "electronics.tablets"
    newCategoryPath: "electronics.mobile.tablets"
  ) {
    id
    name
    categoryPath
  }
}

mutation UpdateProductCategory {
  updateProductCategory(
    productId: 5
    newCategoryPath: "electronics.audio.headphones.premium.sony"
  ) {
    id
    name
    categoryPath
  }
}
