import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '../../../../environments/environment';

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

    constructor(private http: HttpClient) { }

    async getDashboardData(token: string): Promise<any> {
        let reqHeader = new HttpHeaders({ "Authorization": token });
        return await this.http.post("/api/admin/dashboard/getDashboard", {}, { headers: reqHeader })
            .toPromise() as any
    }

    async getPendingApplication(startIndex: number | null, fetchRecords: number | null, token: string): Promise<any> {
        let reqHeader = new HttpHeaders({ "Authorization": token });
        let parameter = JSON.parse(JSON.stringify({ "startIndex": startIndex, "fetchRecords": fetchRecords }));
        return await this.http.post("/api/admin/dashboard/getPendingApplication", parameter, { headers: reqHeader })
            .toPromise() as any
    }

    async getDisbursedData(startIndex: number | null, fetchRecords: number | null, token: string): Promise<any> {
        let reqHeader = new HttpHeaders({ "Authorization": token });
        let parameter = JSON.parse(JSON.stringify({ "startIndex": startIndex, "fetchRecords": fetchRecords }));
        return await this.http.post("/api/admin/dashboard/getDisbursedApplication", parameter, { headers: reqHeader })
            .toPromise() as any
    }

    async getTopPerformer(startIndex: number | null, fetchRecords: number | null, selectedInterval: string, token: string): Promise<any> {
        let reqHeader = new HttpHeaders({ "Authorization": token });
        let parameter = JSON.parse(JSON.stringify({ "startIndex": startIndex, "fetchRecords": fetchRecords, "selectedInterval": selectedInterval }));
        return await this.http.post("/api/admin/dashboard/getTopPerformers", parameter, { headers: reqHeader })
            .toPromise() as any
    }

    async getTop10Performer(token: string): Promise<any> {
        let reqHeader = new HttpHeaders({ "Authorization": token });
        return await this.http.post("/api/admin/dashboard/getTop10Performer", {}, { headers: reqHeader })
            .toPromise() as any
    }
}