import { List, Record } from 'immutable';

export default class Profile extends Record({
  addresses: new List(),
  avatar: null,
  email: null,
  firstName: null,
  generatedNomDeBid: false,
  hasLinkedApple: false,
  hasLinkedFacebook: false,
  hasLinkedGoogle: false,
  hasLocalAccount: false,
  id: null,
  isAllowedToBid: false,
  isOrganizationEmployee: false,
  isVerified: false,
  lastName: null,
  nomDeBid: null,
  organizationIdentifier: null,
  paymentToken: null,
  phones: new List(),
}) {
  get canBid() {
    return this.isAllowedToBid && this.paymentToken !== null;
  }

  get fullName() {
    return `${this.firstName} ${this.lastName}`;
  }

  get isRegisteredAccount() {
    return this.hasLinkedApple ||
      this.hasLinkedFacebook || this.hasLinkedGoogle || this.hasLocalAccount;
  }
}

Profile.fromJS = (data = {}) => {
  return new Profile({
    id: data._id,
    ...data,
    addresses: new List(data.addresses),
    phones: new List(data.phones),
  });
};
