import {
  EHealthProblem,
  ESleepLevel,
  ESport,
  ESportLevel,
} from "./enums/Enums";

export class User {
  private _name?: string;
  private _age?: number;
  private _height?: number;
  private _weight?: number;
  private _sexe?: boolean; // true = Male, false = Female
  private _logo?: string;
  private _nbSessionPerWeek?: number;
  private _goal?: string;
  private _healthProblems?: EHealthProblem[];
  private _sport?: ESport;
  private _sleepLevel?: ESleepLevel;
  private _sportLevel?: ESportLevel;
  private _email?: string;
  private _password?: string;

  constructor({
    name,
    age,
    height,
    weight,
    sexe,
    logo,
    nbSessionPerWeek,
    goal,
    healthProblems,
    sport,
    sleepLevel,
    sportLevel,
    email,
    password,
  }: {
    name?: string;
    age?: number;
    height?: number;
    weight?: number;
    sexe?: boolean;
    logo?: string;
    nbSessionPerWeek?: number;
    goal?: string;
    healthProblems?: EHealthProblem[];
    sport?: ESport;
    sleepLevel?: ESleepLevel;
    sportLevel?: ESportLevel;
    email?: string;
    password?: string;
  } = {}) {
    this._name = name;
    this._age = age;
    this._height = height;
    this._weight = weight;
    this._sexe = sexe;
    this._logo = logo;
    this._nbSessionPerWeek = nbSessionPerWeek;
    this._goal = goal;
    this._healthProblems = healthProblems;
    this._sport = sport;
    this._sleepLevel = sleepLevel;
    this._sportLevel = sportLevel;
    this._email = email;
    this._password = password;
  }

  // Getters
  get name(): string | undefined {
    return this._name;
  }

  get age(): number | undefined {
    return this._age;
  }

  get height(): number | undefined {
    return this._height;
  }

  get weight(): number | undefined {
    return this._weight;
  }

  get sexe(): boolean | undefined {
    return this._sexe;
  }

  get logo(): string | undefined {
    return this._logo;
  }

  get nbSessionPerWeek(): number | undefined {
    return this._nbSessionPerWeek;
  }

  get goal(): string | undefined {
    return this._goal;
  }

  get healthProblems(): EHealthProblem[] | undefined {
    return this._healthProblems;
  }

  get sport(): ESport | undefined {
    return this._sport;
  }

  get sleepLevel(): ESleepLevel | undefined {
    return this._sleepLevel;
  }

  get sportLevel(): ESportLevel | undefined {
    return this._sportLevel;
  }

  get email(): string | undefined {
    return this._email;
  }

  get password(): string | undefined {
    return this._password;
  }

  // Setters
  set name(value: string | undefined) {
    this._name = value;
  }

  set age(value: number | undefined) {
    this._age = value;
  }

  set height(value: number | undefined) {
    this._height = value;
  }

  set weight(value: number | undefined) {
    this._weight = value;
  }

  set sexe(value: boolean | undefined) {
    this._sexe = value;
  }

  set logo(value: string | undefined) {
    this._logo = value;
  }

  set nbSessionPerWeek(value: number | undefined) {
    this._nbSessionPerWeek = value;
  }

  set goal(value: string | undefined) {
    this._goal = value;
  }

  set healthProblems(value: EHealthProblem[] | undefined) {
    this._healthProblems = value;
  }

  set sport(value: ESport | undefined) {
    this._sport = value;
  }

  set sleepLevel(value: ESleepLevel | undefined) {
    this._sleepLevel = value;
  }

  set sportLevel(value: ESportLevel | undefined) {
    this._sportLevel = value;
  }

  set email(value: string) {
    this._email = value;
  }

  set password(value: string) {
    this._password = value;
  }

  public isQuizDone(): boolean {
    return (
      this._name !== undefined &&
      this._age !== undefined &&
      this._height !== undefined &&
      this._weight !== undefined &&
      this._sexe !== undefined &&
      this._nbSessionPerWeek !== undefined &&
      this._goal !== undefined &&
      this._healthProblems !== undefined &&
      this._sport !== undefined &&
      this._sleepLevel !== undefined &&
      this._sportLevel !== undefined
    );
  }

  static fromJSON(json: any): User {
    return new User({
      name: json.name,
      age: json.age,
      height: json.height,
      weight: json.weight,
      sexe: json.sexe,
      logo: json.logo,
      nbSessionPerWeek: json.nbSessionPerWeek,
      goal: json.goal,
      healthProblems: json.healthProblems,
      sport: json.sport,
      sleepLevel: json.sleepLevel,
      sportLevel: json.sportLevel,
      email: json.email,
      password: json.password,
    });
  }

  toJSON(): any {
    return JSON.stringify({
      name: this.name,
      age: this.age,
      height: this.height,
      weight: this.weight,
      sexe: this.sexe,
      logo: this.logo,
      nbSessionPerWeek: this.nbSessionPerWeek,
      goal: this.goal,
      healthProblems: this.healthProblems,
      sport: this.sport,
      sleepLevel: this.sleepLevel,
      sportLevel: this.sportLevel,
      email: this.email,
      password: this.password,
    });
  }
}
