import {Injectable} from '@angular/core';
import {ICollection, ISchema, Resource, Service} from 'ngx-jsonapi';
import {Type, TypesService} from './type.service';
import {App, AppService} from './app.service';

@Injectable()
export class UsersService extends Service<User> {
  public resource = User;
  public type = 'users';
  public schema: ISchema = {
    relationships: {

      type: {
        hasMany: false
      },
      app: {
        hasMany: false
      },
    }
  };
}

export class User extends Resource {
  public attributes: {
    name: string,
    email: string,
    mobile: string,
    password: string,
    lat: string,
    lng: string,
  };
  public getLng() {
    return this.attributes.lng;
  }

  public setLng(lng: string) {
    return this.attributes.lng = lng;
  }
  public getLat() {
    return this.attributes.lat;
  }

  public setLat(lat: string) {
    return this.attributes.lat = lat;
  }
  public getName() {
    return this.attributes.name;
  }

  public setName(name: string) {
    return this.attributes.name = name;
  }

  public getMobile() {
    return this.attributes.mobile;
  }

  public setMobile(Mobile: string) {
    return this.attributes.mobile = Mobile;
  }

  public getPassword() {
    return this.attributes.password;
  }

  public setPassword(Password: string) {
    return this.attributes.password = Password;
  }

  public getEmail() {
    return this.attributes.email;
  }

  public setEmail(Email: string) {
    return this.attributes.email = Email;
  }

  // relationships ke yek be yek hastand

  public getType(): Type {
    return <Type>this.relationships.type.data;
  }

  public setTypeWithId(id: string) {
    const type = (new TypesService()).new();
    type.id = id;
    this.relationships.type.data = type;
  }

  public getApp(): App {
    return <App>this.relationships.app.data;
  }

  public setAppWithId(id: string) {
    const app = (new AppService()).new();
    app.id = id;
    this.relationships.app.data = app;
  }


}
