import { ApiName } from "./ApiName";
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";

@Entity("apiAttribute")
export class ApiAttribute extends EntityBase {
  @Column({
    nullable: false,
    comment: "ชื่อตาราง",
    length: 50,
  })
  tbName: string;

  @Column({
    nullable: false,
    comment: "คีย์ของแอตทริบิวต์",
    length: 255,
  })
  propertyKey: string;

  @Column({
    nullable: false,
    comment: "ลำดับการแสดงผล",
    default: 0,
    type: "int",
  })
  ordering: number;

  @Column({
    nullable: false,
    comment: "ไอดีของ API Name",
    length: 36, // UUID length
  })
  apiNameId: string;

  @ManyToOne(() => ApiName, (apiName) => apiName.apiAttributes)
  @JoinColumn({ name: "apiNameId" })
  apiName: ApiName;
}
