import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { URL } from '../mocks/url';


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

    constructor(
        private http: HttpClient
    ) { }

	async mallsByLocation(latitude: number, longitude: number) {
		const httpOptions = {
			headers: new HttpHeaders({
				'Access-Control-Allow-Origin': '*',
				'Content-Type': 'application/json',
				'Authorization': 'Bearer ' + localStorage.access_Token
			})
		};

		return await this.http.get(URL + '/api/maioraservice/mall/v1/latitude/' + latitude + '/longitude/' + longitude + '/check/', httpOptions).toPromise();
    }
    

    async mallsByTypes(type: string) {
		const httpOptions = {
			headers: new HttpHeaders({
				'Access-Control-Allow-Origin': '*',
				'Content-Type': 'application/json',
				'Authorization': 'Bearer ' + localStorage.access_Token
			})
		};

		return await this.http.get(URL + '/api/maioraservice/mall/v1/outlet_type/' + type + '/', httpOptions).toPromise();
	}

    async allMalls() {
        const httpOptions = {
			headers: new HttpHeaders({
				'Access-Control-Allow-Origin': '*',
				'Content-Type': 'application/json',
				'Authorization': 'Bearer ' + localStorage.access_Token
			})
		};

		return await this.http.get(URL + '/api/maioraservice/mall/getallmalls/', httpOptions).toPromise();
    }


    async updateMallData(mallData: any) {
		const httpOptions = {
			headers: new HttpHeaders({
				'Access-Control-Allow-Origin': '*',
				'Content-Type': 'application/json',
				'Authorization': 'Bearer ' + localStorage.access_Token
			})
		};

		return await this.http.put(URL + '/api/maioraservice/mall/v1/update/', mallData.mall , httpOptions).toPromise();
    }
    

    async updateOutlet(outletData: any) {
		const httpOptions = {
			headers: new HttpHeaders({
				'Access-Control-Allow-Origin': '*',
				'Content-Type': 'application/json',
				'Authorization': 'Bearer ' + localStorage.access_Token
			})
		};

		return await this.http.put(URL + '/api/maioraservice/outlet/v1/update/', outletData , httpOptions).toPromise();
    }
    
    async getBookmarks() {
        const httpOptions = {
			headers: new HttpHeaders({
				'Access-Control-Allow-Origin': '*',
				'Content-Type': 'application/json',
				'Authorization': 'Bearer ' + localStorage.access_Token
			})
		};

		return await this.http.get(URL + '/api/maioraservice/outlet/v1/is_bookmarked/1/', httpOptions).toPromise();
    }
}
