const gql = require('graphql-tag')

const typeDef = gql`
  type MachineStatus {
    label: String!
    type: String!
  }

  type Machine {
    name: String!
    deviceId: ID!
    paired: Boolean!
    lastPing: DateTimeISO
    pairedAt: DateTimeISO
    diagnostics: Diagnostics
    version: String
    model: String
    cashUnits: CashUnits
    numberOfCassettes: Int
    numberOfRecyclers: Int
    statuses: [MachineStatus]
    latestEvent: MachineEvent
    downloadSpeed: String
    responseTime: String
    packetLoss: String
  }

  type Diagnostics {
    timestamp: DateTimeISO
    frontTimestamp: DateTimeISO
    scanTimestamp: DateTimeISO
  }

  type CashUnits {
    cashbox: Int
    cassette1: Int
    cassette2: Int
    cassette3: Int
    cassette4: Int
    recycler1: Int
    recycler2: Int
    recycler3: Int
    recycler4: Int
    recycler5: Int
    recycler6: Int
  }

  input CashUnitsInput {
    cashbox: Int
    cassette1: Int
    cassette2: Int
    cassette3: Int
    cassette4: Int
    recycler1: Int
    recycler2: Int
    recycler3: Int
    recycler4: Int
    recycler5: Int
    recycler6: Int
  }

  type UnpairedMachine {
    id: ID!
    deviceId: ID!
    name: String
    model: String
    paired: DateTimeISO!
    unpaired: DateTimeISO!
  }

  type MachineEvent {
    id: ID
    deviceId: String
    eventType: String
    note: String
    created: DateTimeISO
    age: Float
    deviceTime: DateTimeISO
  }

  enum MachineAction {
    rename
    resetCashOutBills
    setCassetteBills
    unpair
    reboot
    shutdown
    restartServices
    emptyUnit
    refillUnit
    diagnostics
  }

  type Query {
    machines: [Machine] @auth
    machine(deviceId: ID!): Machine @auth
    unpairedMachines: [UnpairedMachine!]! @auth
  }

  type Mutation {
    machineAction(
      deviceId: ID!
      action: MachineAction!
      cashUnits: CashUnitsInput
      newName: String
    ): Machine @auth
  }
`

module.exports = typeDef
