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

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

    constructor(private http: HttpClient) { }

    async getCommissionType(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/commissionTypes/getCommissionType", parameter, { headers: reqHeader })
            .toPromise() as any
    }


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

    async insertUpdateBankLoanCommission(bankId: any, commission: Commission[], token: string): Promise<any> {
        let reqHeader = new HttpHeaders({ "Authorization": token });
        let parameter = JSON.parse(JSON.stringify({ "bankId": bankId, "bankCommissions": commission }))
        return await this.http.post("/api/admin/bankLoanCommission/insertUpdateBankLoanCommission", parameter, { headers: reqHeader })
            .toPromise() as any
    }

    async insertUpdatePartnerLoanCommission(partnerId: number, commission: Commission[], token: string): Promise<any> {
        let reqHeader = new HttpHeaders({ "Authorization": token });
        let parameter = JSON.parse(JSON.stringify({ "partnerId": partnerId, "commissions": commission }))
        return await this.http.post("/api/admin/partnerCommission/insertUpdatePartnerCommission", parameter, { headers: reqHeader })
            .toPromise() as any
    }

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

}