import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';

import 'rxjs/add/operator/map';

import { RESTService } from '@loafer/ng-rest/service';
import { DomainMember } from 'packages/domain/model';

import { Member } from '../model';

@Injectable()
export class MemberService {

  public constructor(
    private restService: RESTService,
  ) {

  }

  public signin(email: string, password: string): Observable<any> {
    return this.restService.request<any>('post', '/account/signin', {
      body: {
        signinID: email,
        signinPW: password,
      },
    });
  }

  public signin_cookie(authToken: string): Observable<DomainMember> {
    return this.restService.request<DomainMember>('post', '/account/signin_cookie', {
      body: {
        authToken: authToken,
      },
    });
  }

  public signup(member: Member, password: string): Observable<Member> {
    return this.restService.request<Member>('post', '/account/signup', {
      body: {
        member: member,
        password: password,
      },
    });
  }
}
