import { Entity, Column, ManyToMany, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { ApiName } from "./ApiName";
import { ApiHistory } from "./ApiHistory";

@Entity("apiKey")
export class ApiKey extends EntityBase {
  @Column({
    nullable: true,
    comment: "ชื่อ",
    length: 255,
    default: null,
  })
  name: string;

  @Column({
    type: 'longtext',
    nullable: true,
    comment: "keyApi",
    default: null,
  })
  keyApi: string;

  @Column({
    nullable: true,
    comment: "accessType",
    length: 40,
    default: null,
  })
  accessType: string;

  @Column({
    nullable: true,
    comment: "dnaRootId",
    length: 40,
    default: null,
  })
  dnaRootId: string;

  @Column({
    nullable: true,
    comment: "dnaChild1Id",
    length: 40,
    default: null,
  })
  dnaChild1Id: string;

  @Column({
    nullable: true,
    comment: "dnaChild2Id",
    length: 40,
    default: null,
  })
  dnaChild2Id: string;

  @Column({
    nullable: true,
    comment: "dnaChild3Id",
    length: 40,
    default: null,
  })
  dnaChild3Id: string;

  @Column({
    nullable: true,
    comment: "dnaChild4Id",
    length: 40,
    default: null,
  })
  dnaChild4Id: string;

  @ManyToMany(() => ApiName, (apiName) => apiName.apiKeys)
  apiNames: ApiName[];

  @OneToMany(() => ApiHistory, (v) => v.apiKey)
  apiHistorys: ApiHistory[];
}

export class CreateApiKey {
  @Column()
  name: string;

  @Column()
  apiId: string[];

  @Column()
  accessType?: string;

  @Column()
  dnaRootId?: string;

  @Column()
  dnaChild1Id?: string;

  @Column()
  dnaChild2Id?: string;

  @Column()
  dnaChild3Id?: string;

  @Column()
  dnaChild4Id?: string;
}
