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

# Only some basic data to be able to display the training

query trainingArchive($skip: Int, $first: Int) {
  trainingArchive(skip: $skip, first: $first) {
    trainings {
      id
      title
      type {
        name
        description
      }
      trainingDate
      location
      attendance
      blocks
    }
    totalCount
  }
}

# The full data set, single item.
query training($id: ID) {
  training(id: $id) {
    ...displayTraining
  }
}

mutation deleteTraining($id: ID!) {
  deleteTraining(id: $id) {
    id
  }
}

# The full data set.
query trainings(
  $where: TrainingWhereInput
  $orderBy: TrainingOrderByInput
  $skip: Int
  $after: String
  $before: String
  $first: Int
  $last: Int
) {
  count: trainingsCount(where: $where) {
    aggregate {
      count
    }
  }
  trainings(
    where: $where
    orderBy: $orderBy
    skip: $skip
    after: $after
    before: $before
    first: $first
    last: $last
  ) {
    ...displayTraining
  }
}

query trainingTypes {
  trainingTypes {
    id
    name
    description
  }
}

query formats {
  formats {
    id
    name
    description
  }
}

query blocks {
  blocks {
    ...blockWithoutBlocks
    blocks {
      ...blockInstanceWithoutBlock
      block {
        ...blockWithoutBlocks
        blocks {
          ...blockInstanceWithoutBlock
          block {
            ...blockWithoutBlocks
          }
        }
      }
    }
  }
}

query exercises {
  exercises {
    ...exerciseContent
  }
}

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) {
    id
  }
}

mutation deregister($training: ID!) {
  deregister(training: $training) {
    id
  }
}

mutation publish($training: ID!, $status: Boolean) {
  publish(training: $training, status: $status) {
    id
  }
}

fragment exerciseContent on Exercise {
  id
  name
  description
  videos {
    id
    title
  }
  pictures {
    id
    title
  }
  targets
  baseExercise
}

fragment blockWithoutBlocks on Block {
  id
  title
  description
  videos {
    id
    title
  }
  pictures {
    id
    title
  }
  duration
  format {
    id
    name
    description
  }
  rest
  exercises {
    id
    exercise {
      ...exerciseContent
    }
    order
    repetitions
    variation
  }
}

fragment blockInstanceWithoutBlock on BlockInstance {
  id
  order
  rounds
  variation
}

fragment displayTraining on Training {
  id
  title
  type {
    id
    name
    description
  }
  createdAt
  trainingDate
  location
  attendance
  published
  blocks {
    ...blockInstanceWithoutBlock
    block {
      ...blockWithoutBlocks
      blocks {
        ...blockInstanceWithoutBlock
        block {
          ...blockWithoutBlocks
          blocks {
            ...blockInstanceWithoutBlock
            block {
              ...blockWithoutBlocks
              blocks {
                ...blockInstanceWithoutBlock
                block {
                  ...blockWithoutBlocks
                  blocks {
                    id
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  registrations {
    id
    name
  }
}

fragment editTraining on Training {
  id
  createdAt
  title
  type {
    id
    name
    description
  }
  createdAt
  trainingDate
  location
  attendance
  published
  blocks {
    ...blockInstanceWithoutBlock
    block {
      ...blockWithoutBlocks
      blocks {
        ...blockInstanceWithoutBlock
        block {
          ...blockWithoutBlocks
          blocks {
            ...blockInstanceWithoutBlock
            block {
              ...blockWithoutBlocks
              blocks {
                ...blockInstanceWithoutBlock
                block {
                  ...blockWithoutBlocks
                  blocks {
                    id
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  registrations {
    id
    name
  }
}
