# import * from '../../../backend/database/generated/prisma.graphql'

fragment exerciseContent on ExerciseInstance {
  id
  exercise {
    id
    name
    description
    videos
    pictures
    targets
    baseExercise
  }
  order
  repetitions
  variation
}

fragment blockContent on Block {
  id
  title
  description
  videos
  pictures
  duration
  format {
    id
    name
    description
  }
  rest
  blocks {
    id
    block {
      ...blockHint
    }
    order
    rounds
    variation
  }
  exercises {
    ...exerciseContent
  }
}

fragment blockHint on Block {
  id
  title
  description
  videos
  pictures
  duration
  format {
    id
    name
    description
  }
  rest
  blocks {
    id
  }
  exercises {
    ...exerciseContent
  }
}

fragment subBlock on BlockInstance {
  id
  block {
    ...blockContent
  }
  order
  rounds
  variation
}

fragment subBlockHint on BlockInstance {
  id
  block {
    ...blockHint
  }
  order
  rounds
  variation
}

query training($id: ID!) {
  training(id: $id) {
    id
    title
    type {
      id
      name
      description
    }
    createdAt
    trainingDate
    location
    attendance
    published
    blocks {
      ...subBlock
    }
    registrations {
      id
      name
    }
  }
}

query trainings {
  trainings {
    id
    title
    type {
      id
      name
      description
    }
    trainingDate
    location
    attendance
    published
    blocks {
      ...subBlockHint
    }
    registrations {
      id
      name
    }
  }
}

query trainingTypes {
  trainingTypes {
    id
    name
    description
  }
}

query formats {
  formats {
    id
    name
    description
  }
}

mutation createTraining(
  $title: String!
  $type: TrainingTypeCreateOneInput!
  $trainingDate: DateTime!
  $location: String!
  $attendance: Int!
  $published: Boolean!
  $blocks: BlockInstanceCreateManyWithoutParentTrainingInput
) {
  createTraining(
    title: $title
    type: $type
    trainingDate: $trainingDate
    location: $location
    attendance: $attendance
    published: $published
    blocks: $blocks
  ) {
    id
  }
}

mutation updateTraining(
  $where: TrainingWhereUniqueInput!
  $data: TrainingUpdateInput!
) {
  updateTraining(where: $where, data: $data) {
    id
  }
}

mutation createTrainingType($name: String!, $description: String!) {
  createTrainingType(name: $name, description: $description) {
    id
  }
}

mutation createFormat($name: String!, $description: String!) {
  createFormat(name: $name, description: $description) {
    id
  }
}

mutation register($training: ID!) {
  register(training: $training)
}
