import gql from 'graphql-tag'

import { client } from '@operato/graphql'

export async function fetchEvaluationStatus(evaluationStatusId: any) {
  var response = (
    await client.query({
      query: gql`
        query EvaluationStatus($evaluationStatusId: String!) {
          evaluationStatus(id: $evaluationStatusId) {
            type
            done
            result
          }
        }
      `,
      variables: { evaluationStatusId }
    })
  ).data

  return response.evaluationStatus
}

export async function createEvaluationStatus(evaluationStatus: any) {
  var response = (
    await client.mutate({
      mutation: gql`
        mutation CreateEvaluationStatus($evaluationStatus: NewEvaluationStatus!) {
          createEvaluationStatus(evaluationStatus: $evaluationStatus) {
            id
            type
            done
          }
        }
      `,
      variables: { evaluationStatus }
    })
  ).data

  return response.createEvaluationStatus
}
