# Organization Chart Query Examples
# Demonstrates LTREE hierarchical operations

# Get all employees
query GetAllEmployees {
  employees {
    id
    name
    title
    department
    orgPath
  }
}

# Find employees under a specific manager
query GetTeam {
  employees(where: {
    orgPath: { descendantOf: "acme.technology.engineering" }
  }) {
    id
    name
    title
    orgPath
  }
}

# Find direct reports (exactly one level down)
query GetDirectReports($managerPath: LTree!) {
  employees(where: {
    orgPath: {
      descendantOf: $managerPath
      nlevelEq: 4  # org.acme.technology.engineering + 1 level
    }
  }) {
    id
    name
    title
  }
}

# Find employees by department pattern
query GetEngineeringTeam {
  employees(where: {
    orgPath: { matchesLquery: "acme.technology.*" }
  }) {
    id
    name
    title
    department
  }
}

# Get organization depth analysis
query GetOrgDepth {
  employees(where: {
    orgPath: { nlevelGte: 4 }
  }) {
    id
    name
    title
    orgPath
  }
}

# Find employees with specific path patterns
query GetManagers {
  employees(where: {
    orgPath: { matchesLquery: "*.manager.*" }
  }) {
    id
    name
    title
    orgPath
  }
}

# Complex hierarchical query: senior engineers in engineering
query GetSeniorEngineers {
  employees(where: {
    orgPath: {
      descendantOf: "acme.technology.engineering"
      matchesLquery: "*.senior.*"
    }
    title: { contains: "Senior" }
  }) {
    id
    name
    title
    salary
    orgPath
  }
}

# Get employee with their hierarchy info
query GetEmployeeHierarchy($id: Int!) {
  employee(id: $id) {
    id
    name
    title
    orgPath
    manager {
      id
      name
      title
    }
    directReports {
      id
      name
      title
    }
    allReports {
      id
      name
    }
  }
}

# Department breakdown
query GetDepartmentBreakdown {
  engineering: employees(where: {
    department: { eq: "Engineering" }
  }) {
    id
    name
    title
  }

  product: employees(where: {
    department: { eq: "Product" }
  }) {
    id
    name
    title
  }

  sales: employees(where: {
    department: { eq: "Sales" }
  }) {
    id
    name
    title
  }
}

# Salary analysis by hierarchy level
query GetSalaryByLevel {
  executives: employees(where: {
    orgPath: { nlevelLte: 3 }
  }) {
    name
    title
    salary
    orgPath
  }

  managers: employees(where: {
    orgPath: { matchesLquery: "*.manager.*" }
  }) {
    name
    title
    salary
  }

  individualContributors: employees(where: {
    orgPath: { nlevelGte: 5 }
  }) {
    name
    title
    salary
  }
}

# Recent hires in hierarchy
query GetRecentHires {
  employees(where: {
    hireDate: { gte: "2021-01-01" }
    orgPath: { descendantOf: "acme.technology" }
  }) {
    id
    name
    title
    hireDate
    orgPath
  }
}

# Organization structure visualization
query GetOrgStructure {
  orgStructure(rootPath: "acme.technology") {
    id
    name
    title
    orgPath
  }
}

# Mutation examples
mutation AddNewEmployee {
  addEmployee(
    name: "Sarah Connor"
    title: "Senior Engineer"
    department: "Engineering"
    salary: 115000
    managerId: 5  # Eva Garcia's ID
    hireDate: "2024-01-15"
  ) {
    id
    name
    title
    orgPath
  }
}

mutation UpdateEmployeePosition {
  updateEmployeePosition(
    employeeId: 8  # Frank Miller
    newManagerId: 6  # Ivy Chen (Frontend Manager)
    newTitle: "Senior Frontend Engineer"
  ) {
    id
    name
    title
    orgPath
    manager {
      name
      title
    }
  }
}
