import { Exclude } from "class-transformer";
import { IsEmail, Length } from "class-validator";
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryGeneratedColumn, Unique } from "typeorm";
import { Friendship } from "../../friendship/entities/friendship.entity";
import { UserStats } from "./userStat.entities";


@Entity('user')
@Unique(['email', 'username'])
export class User {

	@PrimaryGeneratedColumn()
	id: number;

	@Column({unique: true})
	fortyTwoId: string;

	@Column()
	username: string;

	@Column()
	@IsEmail()
	email: string;

	@Column()
	image_url : string;

	@Column({ nullable: true })
	phone: string;

	@Column({ default: 'disconnected' })
	status: string;

	// @Column()
	// isFirstConnection: boolean;

	@Column({ default: false, nullable: true })
	isEnabledTwoFactorAuth: boolean;

	@Column({ default:false, nullable: true })
	isTwoFactorAuthenticated: boolean;

	@Column({ nullable: true })
	secretTwoFactorAuth: string;

	@OneToMany(type => Friendship , (friendship) => friendship.sender)
	sentFriendRequest: Friendship[];

	@OneToMany(type => Friendship , (friendship) => friendship.receiver)
	receivedFriendRequest: Friendship[];

	@JoinColumn()
	@OneToOne(() => UserStats, { cascade: true })
	stats: UserStats;
}
