import { Account } from '../../../repositories/accounts/entity/account.entity';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
  OneToOne,
  OneToMany,
} from 'typeorm';
import { License } from '../../licenses/entity/license.entity';
import { UserGroupMember } from '../../user_groups/entity/user_group_member.entity';

@Entity({ name: 'users' })
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  external_id: string;

  @Column()
  account_id: number;

  @Column()
  role: string;

  @Column({ nullable: true })
  author_id?: string;

  @Column()
  accepted_terms_version: string;

  @Column()
  email_verified: boolean;

  @Column()
  auto_renew: boolean;

  @Column()
  license_alert: boolean;

  @Column()
  notification: boolean;

  @Column()
  encryption: boolean;

  @Column()
  prompt: boolean;

  @Column({ nullable: true })
  deleted_at?: Date;

  @Column()
  created_by: string;

  @CreateDateColumn()
  created_at: Date;

  @Column()
  updated_by: string;

  @UpdateDateColumn()
  updated_at: Date;

  @ManyToOne(() => Account, (account) => account.user)
  @JoinColumn({ name: 'account_id' })
  account?: Account;

  @OneToOne(() => License, (license) => license.user)
  license?: License;

  @OneToMany(() => UserGroupMember, (userGroupMember) => userGroupMember.user)
  userGroupMembers?: UserGroupMember[];
}
