import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Worktype } from './worktype.entity';

@Entity({ name: 'option_items' })
export class OptionItem {
  @PrimaryGeneratedColumn()
  id: number;
  @Column()
  worktype_id: number;
  @Column()
  item_label: string;
  @Column()
  default_value_type: string;
  @Column()
  initial_value: string;
  @Column({ nullable: true, type: 'datetime' })
  created_by: string | null;
  @CreateDateColumn({
    default: () => "datetime('now', 'localtime')",
    type: 'datetime',
  }) // defaultはSQLite用設定値.本番用は別途migrationで設定
  created_at: Date | null;
  @Column({ nullable: true, type: 'datetime' })
  updated_by: string | null;
  @UpdateDateColumn({
    default: () => "datetime('now', 'localtime')",
    type: 'datetime',
  }) // defaultはSQLite用設定値.本番用は別途migrationで設定
  updated_at: Date | null;

  @ManyToOne(() => Worktype, (worktype) => worktype.id)
  @JoinColumn({ name: 'worktype_id' })
  worktype: Worktype;
}
