type User {
    id: ID! @id
    email: String! @unique
    name: String!
    password: String!
    resetToken: String
    resetTokenExpiry: Float
    createdAt: DateTime! @createdAt
    comments: [Comment!]!
    ratings: [Rating!]!
    permissions: [Permission!]!  @scalarList(strategy: RELATION)
    interests: [String!]!  @scalarList(strategy: RELATION)
}

enum Permission {
    ADMIN
    INSTRUCTOR
}

type File {
    id: ID! @id
    createdAt: DateTime! @createdAt
    updatedAt: DateTime! @updatedAt
    path: String!
    mimetype: String!
    user: User!
    thumbnail: String
    filename: String!
    encoding: String!
    size: Int!
    comment: String
}

type Training {
    id: ID! @id
    title: String!
    type: TrainingType!
    createdAt: DateTime! @createdAt
    trainingDate: DateTime!
    location: String!
    registrations: [User!]!
    attendance: Int
    ratings: [Rating!]!
    published: Boolean!
    blocks: [BlockInstance!]! @relation(onDelete: CASCADE)
}

type TrainingType {
    id: ID! @id
    name: String! @unique
    description: String!
}

type Block {
    id: ID! @id
    title: String!
    description: String
    videos: [String!]! @scalarList(strategy: RELATION)
    pictures: [String!]! @scalarList(strategy: RELATION)
    duration: Int
    format: Format!
    rest: Int
    tracks: [Track!]!
    blocks: [BlockInstance!] @relation(name: "Instances", onDelete: CASCADE)
    links: [BlockInstance!]! @relation(name: "ParentChild", onDelete: CASCADE)
    exercises: [ExerciseInstance!]! @relation(onDelete: CASCADE)
}

type BlockInstance {
    id: ID! @id
    block: Block! @relation(name: "ParentChild", onDelete: SET_NULL)
    parentBlock: Block @relation(name: "Instances")
    parentTraining: Training @relation(link: INLINE)
    order: Int!
    rounds: Int
    variation: String
}

type Format {
    id: ID! @id
    name: String!
    description: String!
}

type Track {
    id: ID! @id
    title: String!
    artist: String!
    duration: Int!
    link: String!
}

type Exercise {
    id: ID! @id
    name: String!
    description: String
    videos: [String!]! @scalarList(strategy: RELATION)
    pictures: [String!]! @scalarList(strategy: RELATION)
    targets: [String!]! @scalarList(strategy: RELATION)
    baseExercise: [String!]! @scalarList(strategy: RELATION)
}

type ExerciseInstance {
    id: ID! @id
    exercise: Exercise! @relation(link: INLINE)
    order: Int!
    repetitions: Int
    variation: String
}

type Rating {
    id: ID! @id
    user: User!
    value: Int!
    comment: String!
    createdAt: DateTime! @createdAt
}

type Comment {
    id: ID! @id
    text: String!
    author: User!
    createdAt: DateTime! @createdAt
}