import { Account } from '../../accounts/entity/account.entity';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  OneToMany,
} from 'typeorm';
import { OptionItem } from './option_item.entity';

@Entity({ name: 'worktypes' })
export class Worktype {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  account_id: number;

  @Column()
  custom_worktype_id: string;

  @Column({ nullable: true, type: 'varchar' })
  description: string | null;

  @Column({ nullable: true, type: 'datetime' })
  deleted_at: Date | null;

  @Column({ nullable: true, type: 'datetime' })
  created_by: string | null;

  @CreateDateColumn({
    default: () => "datetime('now', 'localtime')",
    type: 'datetime',
  }) // defaultはSQLite用設定値.本番用は別途migrationで設定
  created_at: Date;

  @Column({ nullable: true, type: 'datetime' })
  updated_by: string | null;

  @UpdateDateColumn({
    default: () => "datetime('now', 'localtime')",
    type: 'datetime',
  }) // defaultはSQLite用設定値.本番用は別途migrationで設定
  updated_at: Date;

  @OneToMany(() => OptionItem, (optionItem) => optionItem.worktype)
  option_items: OptionItem[];
}
