import { User } from '../../../repositories/users/entity/user.entity';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  JoinColumn,
  ManyToOne,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';
import { UserGroup } from './user_group.entity';

@Entity({ name: 'user_group_member' })
export class UserGroupMember {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  user_group_id: number;

  @Column()
  user_id: number;

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

  @ManyToOne(() => User, (user) => user.id)
  @JoinColumn({ name: 'user_id' })
  user: User | null;

  @ManyToOne(() => UserGroup, (userGroup) => userGroup.id)
  @JoinColumn({ name: 'user_group_id' })
  userGroup: UserGroup | null;
}
