import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';

import 'rxjs/add/operator/toPromise';

import { AshaWorkerBasicDetailsModel } from '../model/asha-worker-basic-details-model';
import { AshaWorkersList, DummyAshaWorkerDetails } from './temporary/temp-data';


@Injectable()
export class AshaWorkersDetailsService{

    private url: string = "http://www.ashavizianagaram.in:81/ashaservices/webapi/getdetails/get_asha_worker_details";

    constructor(private http: Http){}

    getAshaWorkersList(): Promise<AshaWorkerBasicDetailsModel[]>{
        //return Promise.resolve(AshaWorkersList);
        return this.http.get(this.url)
                    .toPromise()
                    .then(response => response.json().a)
                        
                    .catch(this.handleError);
    }

    getDummyAshaWorkerDetails(): Promise<AshaWorkerBasicDetailsModel>{
        return Promise.resolve(DummyAshaWorkerDetails);
    }

        console.error('An error occured', error);
        return Promise.reject(error.message || error);
    }
}
    private handleError(error: any):Promise<any>{