import { BaseEntity } from "@edr/api-common";
import { Column, Entity, Index, OneToMany } from "typeorm";

import { DropdownOption } from "./dropdown-option.entity";

export interface DropdownSettingMeta {
  icon?: string;
  color?: string;
  searchable?: boolean;
  clearable?: boolean;
  permissions?: string[];
  version?: string;
}

@Entity({schema:"freight", name: "dropdown_settings" })
@Index(["code"], { unique: true })
export class DropdownSetting extends BaseEntity {
  @Column({ name: "code", type: "varchar", length: 128, unique: true })
  code!: string;

  @Column({ name: "label", type: "varchar", length: 256 })
  label!: string;

  @Column({ name: "description", type: "text", nullable: true })
  description?: string | null;

  @Column({ name: "multiple", type: "boolean", default: false })
  multiple!: boolean;

  @Column({ name: "meta", type: "jsonb", nullable: true })
  meta?: DropdownSettingMeta | null;

  @OneToMany(() => DropdownOption, (option) => option.setting, {
    cascade: true,
  })
  children!: DropdownOption[];
}
