import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { SearchService } from '../../oneit/services/search.service';
import { UtilsService } from '../../oneit/services/utils.service';

@Injectable()
export class EditWorkflowTemplateService {

    constructor(
        private searchService: SearchService,
        private utilsService: UtilsService
    ) {
    }

    getDummy456s(assocs): Observable<any> {
        return this.searchService.getObjects('MessageTemplates', 'All', {}, assocs, null, null, null, null)
            .map(
                data =>
                    this.utilsService.convertResponseToObjects(data, assocs)
            );
    }

    getmessagetemplate_withdrawsForAutocomplete(searchTerm, assocs): Observable<any> {
        return this.searchService.getObjects('', 'All', {}, assocs, null, null, null, null)
            .map(
                data =>
                    this.utilsService.convertResponseToObjects(data, assocs)
            );
    }

    getmessagetemplatesForAutocomplete(searchTerm, assocs): Observable<any> {
        return this.searchService.getObjects('', 'All', {}, assocs, null, null, null, null)
            .map(
                data => {
                    return this.utilsService.convertResponseToObjects(data, assocs);
                }
            );
    }

    getWorkflowTemplateByID(id, assocs): Observable<any> {
        return this.searchService.getObjectById('', id, assocs)
            .map(
                data => {
                    const objs = this.utilsService.convertResponseToObjects(data, assocs);

                    if (objs && objs.length > 0) {
                        return objs[0];
                    }
                }
            );
    }

}
