import { CreateDateColumn, Entity, Index, Column, RelationId, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'

import { Domain } from '@things-factory/shell'
import { User } from '@things-factory/auth-base'

@Entity('route_label_sequence_logs')
@Index('ix_route_label_sequence_logs_0', (l: RouteLabelSequenceLog) => [
  l.domain,
  l.releaseGoodId,
  l.field,
  l.createdAt
])
@Index('ix_route_label_sequence_logs_1', (l: RouteLabelSequenceLog) => [l.domain, l.field, l.createdAt])
export class RouteLabelSequenceLog {
  @PrimaryGeneratedColumn('uuid')
  readonly id: string

  @ManyToOne(type => Domain)
  domain?: Domain

  @RelationId((l: RouteLabelSequenceLog) => l.domain)
  domainId?: string

  @Column()
  releaseGoodId: string

  @Column()
  field: string

  @Column({ type: 'int' })
  from: number

  @Column({ type: 'int' })
  to: number

  @Column({ type: 'int' })
  qty: number

  @CreateDateColumn()
  createdAt?: Date

  @ManyToOne(type => User, { nullable: true })
  creator?: User

  @RelationId((l: RouteLabelSequenceLog) => l.creator)
  creatorId?: string
}
