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

@Injectable()
export class AlarmService {

    constructor(private http: HttpClient) {
    }

    //告警list
    eventFind(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/alertLog/page', data);
    }

    //告警推送日志
    alertFind(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/alert/find', data);
    }

    //删除告警推送日志
    alertDelete(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/alert/delete', data);
    }

    //查询告警推送设置
    actionFind(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/action/find', data);
    }

    //查询单个告警推送设置
    getAction(params): Observable<any> {
        return this.http.get(SERVER_API_URL + '/action/find/' + params);
    }

    //查找所有zabbix用户
    zUserFind(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/zuser/find', data);
    }

    //修改告警推送设置
    actionUpdate(data): Observable<any> {
        return this.http.put(SERVER_API_URL + '/action/update', data);
    }

    //创建告警推送设置
    actionCreate(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/action/create', data);
    }

    //单个启用或禁用告警推送设置
    actionStatus(params1, params2): Observable<any> {
        return this.http.post(SERVER_API_URL + '/action/status/' + params1 + '/' + params2, null);
    }

    //批量启用或禁用告警设置
    actionStatusBatch(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/action/status-batch', data);
    }

    //批量删除告警推送设置
    actionDelete(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/action/delete', data);
    }

    //查询所有告警组
    alertGroupFind(): Observable<any> {
        return this.http.get(SERVER_API_URL + '/alertGroup/findAll');
    }

    //创建告警组
    alertGroupCreate(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/alertGroup/create', data);
    }

    //修改告警组
    alertGroupUpdate(data): Observable<any> {
        return this.http.put(SERVER_API_URL + '/alertGroup/update', data);
    }

    //删除告警组
    alertGroupDelete(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/alertGroup/delete', data);
    }

    //发送方式列表
    mediaTypeFind(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/mediaType/find', data);
    }

    //添加发送方式
    mediaTypeCreate(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/mediaType/create', data);
    }

    //删除发送方式
    mediaTypeDelete(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/mediaType/delete', data);
    }

    //修改发送方式
    mediaTypeUpdate(data): Observable<any> {
        return this.http.put(SERVER_API_URL + '/mediaType/update', data);
    }

    //单个启用或禁用发送方式
    mediaTypeStatus(params1, params2): Observable<any> {
        return this.http.post(SERVER_API_URL + '/mediaType/status/' + params1 + '/' + params2, null);
    }

    //批量启用或禁用发送方式
    mediaTypeStatusBatch(data): Observable<any> {
        return this.http.put(SERVER_API_URL + '/mediaType/status-batch', data);
    }

    //查询发送方式详情
    getMediaType(params): Observable<any> {
        return this.http.get(SERVER_API_URL + '/mediaType/find/' + params);
    }

    //查找告警目标
    findAlertTarget(): Observable<any> {
        return this.http.get(SERVER_API_URL + '/action/findAlertTarget');
    }

    //导出当前告警列表
    getExportUrlEvent(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/event/getExportUrl', data);
    }

    //告警推送日志导出
    getExportUrlAlert(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/alert/getExportUrl', data);
    }
}
