import { Entity, Index, Column, RelationId, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
import { ObjectType, Field, Int, ID } from 'type-graphql'

import { ScalarObject } from '@things-factory/shell'
import { Process } from '../process/process'

@Entity()
@Index('ix_analysis_0', (analysis: Analysis) => [analysis.process], { unique: true })
@ObjectType({ description: 'Entity for Design Analysis' })
export class Analysis {
  @PrimaryGeneratedColumn('uuid')
  @Field(type => ID)
  readonly id: string

  @ManyToOne(type => Process, { onDelete: 'CASCADE' })
  @Field({ nullable: true })
  process?: Process

  @RelationId((analysis: Analysis) => analysis.process)
  processId?: string

  @Column('simple-json', { nullable: true })
  @Field(type => ScalarObject, { nullable: true })
  model?: any

  @Column('simple-json', { nullable: true })
  @Field(type => ScalarObject, { nullable: true })
  dag?: any

  @Column('simple-json', { nullable: true })
  @Field(type => ScalarObject, { nullable: true })
  result?: any

  @Column({ nullable: true })
  @Field({ nullable: true })
  availiability?: boolean

  @Column({ nullable: true })
  @Field({ nullable: true })
  availDetail?: string
}
