import { Injectable } from '@angular/core';
import 'rxjs/add/operator/toPromise';

import { UserProfile } from '../../shared';

const userProfile: UserProfile[] = [
  { password: "", confirmPassword: "", user: { id: 1, firstName: "UserFirstname1", lastName: "UserLastname1", email: "UserFirstname1.UserLastname1@xpo.com", phoneNumber: "0000-000-0001" } },
  { password: "", confirmPassword: "", user: { id: 2, firstName: "UserFirstname2", lastName: "UserLastname2", email: "UserFirstname2.UserLastname2@xpo.com", phoneNumber: "0000-000-0002" } },
  { password: "", confirmPassword: "", user: { id: 3, firstName: "UserFirstname3", lastName: "UserLastname3", email: "UserFirstname3.UserLastname3@xpo.com", phoneNumber: "0000-000-0003" } },
  { password: "", confirmPassword: "", user: { id: 4, firstName: "UserFirstname4", lastName: "UserLastname4", email: "UserFirstname4.UserLastname4@xpo.com", phoneNumber: "0000-000-0004" } },
];

@Injectable()
export class UserProfileService {
  updateProfileInfo: UserProfile;

  setUpdatedUserProfile(updateProfileInfo: UserProfile) {
    let url = this.getUserProfile("Query for saving profile");
    return new Promise((resolve, reject) => {
      resolve(updateProfileInfo);
    });
  }

  constructor() { }

  getUserProfile(userId): Promise<UserProfile> {
    let currentUserProfile: UserProfile;
    for (let profile of userProfile) {
      if (profile.user.id == userId) {
        currentUserProfile = new UserProfile(profile.password, profile.confirmPassword, profile.user);
      }
    }
    return new Promise((resolve, reject) => {
      resolve(currentUserProfile);
    });

  }
}
