import { gql } from "@apollo/client";

export const QUERY_TEAMS = gql`
  query QUERY_TEAMS {
    employee_teams(order_by: { name: asc }) {
      id
      max_load
      name
      employee_team_members {
        id
        employeeid
        labor_rates
        payout_method
        commission_rates
        percentage
      }
    }
  }
`;

export const UPDATE_EMPLOYEE_TEAM = gql`
  mutation UPDATE_EMPLOYEE_TEAM(
    $employeeTeamId: uuid!
    $employeeTeam: employee_teams_set_input
    $teamMemberDeletes: [uuid!]
    $teamMemberUpdates: [employee_team_members_updates!]!
    $teamMemberInserts: [employee_team_members_insert_input!]!
  ) {
    update_employee_team_members_many(updates: $teamMemberUpdates) {
      returning {
        employeeid
        id
        labor_rates
        payout_method
        commission_rates
        percentage
      }
    }
    delete_employee_team_members(where: { id: { _in: $teamMemberDeletes } }) {
      affected_rows
    }
    insert_employee_team_members(objects: $teamMemberInserts) {
      returning {
        employeeid
        id
        labor_rates
        payout_method
        commission_rates
        percentage
      }
    }
    update_employee_teams_by_pk(pk_columns: { id: $employeeTeamId }, _set: $employeeTeam) {
      active
      id
      max_load
      name
      employee_team_members {
        employeeid
        id
        labor_rates
        payout_method
        commission_rates
        percentage
      }
    }
  }
`;

export const INSERT_EMPLOYEE_TEAM = gql`
  mutation INSERT_EMPLOYEE_TEAM($employeeTeam: employee_teams_insert_input!) {
    insert_employee_teams_one(object: $employeeTeam) {
      active
      id
      max_load
      name
      employee_team_members {
        employeeid
        id
        labor_rates
        payout_method
        commission_rates
        percentage
      }
    }
  }
`;

export const QUERY_EMPLOYEE_TEAM_BY_ID = gql`
  query QUERY_EMPLOYEE_TEAM_BY_ID($id: uuid!) {
    employee_teams_by_pk(id: $id) {
      active
      id
      max_load
      name
      employee_team_members {
        employeeid
        id
        labor_rates
        payout_method
        commission_rates
        percentage
      }
    }
  }
`;
