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

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

    constructor(private http: HttpClient) { }

    async getLanguage(startIndex: any, fetchRecords: any): Promise<any> {
        let parameter = JSON.parse(JSON.stringify({ "startIndex": startIndex, "fetchRecords": fetchRecords }))
        return await this.http.post("/api/admin/language/get", parameter)
            .toPromise() as any
    }

    async insertUpdateLanguage(id: number, language: string, code: string, token: string): Promise<any> {
        let reqHeader = new HttpHeaders({ "Authorization": token });
        let parameter = JSON.parse(JSON.stringify({ "id": id, "language": language, "code": code }));
        return await this.http.post("/api/admin/language/insertUpdateLanguage", parameter, { headers: reqHeader })
            .toPromise() as any
    }

    async activeInactiveLanguage(id: number, isActive: boolean, token: string): Promise<any> {
        let parameter = JSON.parse(JSON.stringify({ "id": id, "isActive": isActive }))
        let reqHeader = new HttpHeaders({ "Authorization": token });
        return await this.http.post("/api/admin/language/activeInactiveLanguage", parameter, { headers: reqHeader })
            .toPromise() as any;
    }

}