import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
    providedIn: 'root'
})
export class OperationalConsultationService {

    constructor(protected http: HttpClient) {

    }

    get serviceURL(): string {
        return './dashboard/operative';
    }

    getSummary(startDate: Date, endDate: Date, channel: string) {
        const diff= (Math.trunc((endDate.getTime()-startDate.getTime())/1000))/60;

        console.log(diff)

        if(diff>=43200) return this.http.post(this.serviceURL, {startDate, endDate, channel, rangeMinutes: 1440});
        else if(diff>=1440) return this.http.post(this.serviceURL, {startDate, endDate, channel, rangeMinutes: 300});
        else if(diff>=120) return this.http.post(this.serviceURL, {startDate, endDate, channel, rangeMinutes: 30});
        else if(diff>=50) return this.http.post(this.serviceURL, {startDate, endDate, channel, rangeMinutes: 10});
        else return this.http.post(this.serviceURL, {startDate, endDate, channel, rangeMinutes: 5});

    }

}
