import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {SERVER_API_URL} from '../app.constants';
import {Observable} from 'rxjs/Rx';
import {CommonService} from '../shared/common/common.service';

@Injectable()
export class BusinessService {

    constructor(private http: HttpClient,private commonSer:CommonService) {
    }

    //添加分组
    createService(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/itservice/create', data);
    }

    //编辑分组
    updateService(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/itservice/update', data);
    }

    //删除服务
    deleteService(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/itservice/delete', data);
    }

   //查询业务树
    findChild(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/itservice/findChild', data);
    }

    //查找业务列表(不具有层级关系)
    findList(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/itservice/findList', data);
    }

    //关联网站监测
    relatedHttptest(paramsServiceId,paramshttpestId): Observable<any> {
        return this.http.get(SERVER_API_URL + '/itservice/relatedHttptest/'+paramsServiceId+"/"+paramshttpestId);
    }

    //查询告警时间
    selectAlarmsClock(params): Observable<any> {
        return this.http.get(SERVER_API_URL + '/itservice/selectAlarmsClock/'+params);
    }

    //查询业务概览统计
    itserviceOverview(): Observable<any> {
        return this.http.get(SERVER_API_URL + '/itserviceOverview/count');
    }

    //运行报告列表
    serviceSla(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/itserviceOverview/serviceSla',data);
    }

    //保存业务拓扑图
    serviceTopologySave(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/serviceTopology/save',data);
    }

    //查找业务拓扑图
    serviceTopologyFind(params): Observable<any> {
        return this.http.get(SERVER_API_URL + '/serviceTopology/find/'+params);
    }

    //查询业务根节点列表(业务拓扑中业务下拉框接口)
    findRoot(): Observable<any> {
        return this.http.get(SERVER_API_URL + '/itservice/findRoot');
    }

    //分页查询列表
    findPage(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/itservice/findPage',data);
    }

    //监测点列表
    triggerList(params): Observable<any> {
        return this.http.get(SERVER_API_URL + '/serviceAnalysis/triggerList/'+ params);
    }

    //查询根业务以及子业务下的所有网站监测
    findHttptest(params): Observable<any> {
        return this.http.get(SERVER_API_URL + '/serviceAnalysis/findHttptest/'+ params);
    }

    //系统可用性, 监测点, 用户统计
    serviceAnalysisCount(params): Observable<any> {
        return this.http.get(SERVER_API_URL + '/serviceAnalysis/count/'+ params);
    }

    //获取用户趋势
    userCount(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/serviceAnalysis/userCount',data);
    }
}
