import gql from 'graphql-tag';

export const query = gql`
  query allocationGraph($deviceId: String!, $direction: String!, $allocationBody: any) {
    response(
      deviceId: $deviceId, direction: $direction
    ) @rest(
      type: "Device",
      path: "/devices/{args.deviceId}",
      endpoint: "connections",
    ) {
      device: content @export(as: "device") {
        startDate
        endDate
      }
      allocation: content @type(name: "allocation")  {
        content @rest(
          type: "AllocationIntervals",
          path: "/dashboard/interval",
          endpoint: "proxy",
          method: "post",
          bodyBuilder: $allocationBody,
        ) {
          records: content @type(name: "records") {
            aggregationType
            totalValue
            periods: data @type(name: "periods") {
              period
              types: data @type(name: "types") {
                backup
                category
                energyType
                period
                type
                value
              }
            }
          }
        }
      }
    }
  }
`;
