import { bigintTransformer } from '../../../common/entity';
import { User } from '../../../repositories/users/entity/user.entity';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  OneToMany,
} from 'typeorm';

@Entity({ name: 'accounts' })
export class Account {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ nullable: true, type: 'bigint', transformer: bigintTransformer })
  parent_account_id: number | null;

  @Column()
  tier: number;

  @Column()
  country: string;

  @Column({ default: false })
  delegation_permission: boolean;

  @Column({ default: false })
  locked: boolean;

  @Column()
  company_name: string;

  @Column({ default: false })
  verified: boolean;

  @Column({ nullable: true, type: 'bigint', transformer: bigintTransformer })
  primary_admin_user_id: number | null;

  @Column({ nullable: true, type: 'bigint', transformer: bigintTransformer })
  secondary_admin_user_id: number | null;

  @Column({ nullable: true, type: 'bigint', transformer: bigintTransformer })
  active_worktype_id: number | 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(() => User, (user) => user.id)
  user: User[] | null;
}
