# Generic Types

"Multi-purpose meta information field"
type Meta {
  "Unique id in the database"
  id: ID! @unique
  "Key for the meta information"
  key: String!
  "Value of the meta information"
  value: String!
}

type User {
  id: ID! @unique
  email: String! @unique
  name: String!
  abbreviation: String!
  password: String!
  images: [File]!
  comments: [Comment]! @relation(name: "CommentAuthor", onDelete: CASCADE)
}

type File {
  id: ID! @unique
  path: String!
  name: String
  description: String
  filename: String!
  mimetype: String!
  encoding: String!
  size: Int!
}

type Comment {
  id: ID! @unique
  text: String
  createdAt: DateTime!
  author: User! @relation(name: "CommentAuthor", onDelete: SET_NULL)
}

type Event {
  id: ID! @unique  
  json: String!
  when: DateTime!
}


# Project Information

type Project {
  id: ID! @unique
  name: String! @unique
  abbreviation: String! @unique
  description: String
  files: [File]!
  versions: [ProjectVersion]!
}

type ProjectVersion {
  id: ID! @unique
  name: String! @unique
  changes: [String]!
  date: DateTime!
  project: Project!
}


# Instruments

type InstrumentParameter {
  id: ID! @unique
  tag: String!
  name: String
  description: String
  type: String!
  values: String
  instrument: Instrument! @relation(name: "Parameters", onDelete: SET_NULL)
  commands: [InstrumentCommand]! @relation(name: "CommandParameters", onDelete: SET_NULL)
}

type InstrumentCommand {
  id: ID! @unique
  tag: String!
  name: String
  description: String!
  readString: String
  writeString: String
  subsystem: String
  parameters: [InstrumentParameter]! @relation(name: "CommandParameters", onDelete: SET_NULL)
}

type Instrument {
  id: ID! @unique
  name: String!
  manufacturer: String!
  description: String
  picture: ID
  documents: [File]! 
  interfaces: [String]!
  commands: [InstrumentCommand]!
  parameters: [InstrumentParameter]! @relation(name: "Parameters", onDelete: CASCADE)
  instances: [InstrumentInstance]! @relation(name: "InstrumentInstances", onDelete: CASCADE)
}

type InstrumentInstance {
  id: ID! @unique
  instrument: Instrument! @relation(name: "InstrumentInstances", onDelete: SET_NULL)
  identifier: String!
  label: String
  location: String
}


# DUT

type DUT {
  id: ID! @unique
  name: String!
  description: String
  project: ProjectVersion!
  modifications: [String]!
}


# Setup

type SetupHardware {
  id: ID! @unique
  name: String!
  description: String
  images: [File]!
}

type SetupHardwareInstance {
  id: ID! @unique
  setupHardware: SetupHardware!
  identifier: String!
  images: [File]!
}

type Setup {
  id: ID! @unique
  name: String!
  description: String!
  images: [File]!
  comments: [Comment]!
  setupHardware: [SetupHardwareInstance]!
  instruments: [InstrumentInstance]!
}


# Measurement

type Measurement {
  id: ID! @unique
  createdAt: DateTime!
  intValue: Int
  floatValue: Float
  stringValue: String
}

type MeasurementRun {
  id: ID! @unique
  name: String!
  operators: [User]!
  location: String!
  temperature: Float
  startTime: DateTime!
  endTime: DateTime!
  log: [Event]!
  comments: [Comment]!
  measurements: [Measurement]!
  setup: Setup!
}


# Characterization

type Characterization {
  id: ID! @unique
  name: String!
  projectVersion: ProjectVersion!
  measurementRuns: [MeasurementRun]!
}