import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '../../../../environments/environment';
import { GiftProduct } from '../../models/gift-product';

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

    constructor(private http: HttpClient) { }

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

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

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

}