import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  OneToMany,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';
import { UserGroupMember } from './user_group_member.entity';

@Entity({ name: 'user_group' })
export class UserGroup {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  account_id: number;

  @Column()
  name: string;

  @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 | null;

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

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

  @OneToMany(
    () => UserGroupMember,
    (userGroupMember) => userGroupMember.userGroup,
  )
  userGroupMembers: UserGroupMember[] | null;
}
