import { CreateDateColumn, UpdateDateColumn, Entity, Index, Column, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
import { Domain } from '@things-factory/shell'
import { User } from '@things-factory/auth-base'

@Entity()
@Index('ix_domain_secret_0', (domainSecret: DomainSecret) => [domainSecret.domain, domainSecret.secret], {
  unique: true
})
export class DomainSecret {
  @PrimaryGeneratedColumn('uuid')
  id: String

  @ManyToOne(type => Domain)
  domain: Domain

  @Column()
  secret: String

  @CreateDateColumn()
  createdAt: Date

  @UpdateDateColumn()
  updatedAt: Date

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

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