import { Injectable } from '@angular/core';
import { HTTP } from '@ionic-native/http/ngx';
import { HttpClient } from '@angular/common/http';
import { Platform } from '@ionic/angular';

export const IMAGE_BASE_URL: string = 'https://www.punjabkingsipl.in/static-assets/waf-images/';

@Injectable({
    providedIn: 'root'
})
export class NewsService {
    constructor(
        private http: HTTP,
        private httpClient: HttpClient,
        private platform: Platform
    ) { }

    getArticles() {
        if (this.platform.is('android') || this.platform.is('capacitor')) {
            return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=4&otherent=1,8021&pgnum=1&inum=10&pgsize=10', {}, {});
        } else {
            return this.httpClient.get('https://www.punjabkingsipl.in/api/listing?entities=4&otherent=1,8021&pgnum=1&inum=10&pgsize=10').toPromise();
        }
    }

    getArticleDetails(title_alias_from_listing_api: string) {
        if (this.platform.is('android') || this.platform.is('capacitor')) {
            return this.http.get('https://www.punjabkingsipl.in/api/article/' + title_alias_from_listing_api + '?is_app=1', {}, {});
        } else {
            return this.httpClient.get('https://www.punjabkingsipl.in/api/article/' + title_alias_from_listing_api + '?is_app=1').toPromise();
        }
    }

    getVideos() {
        if (this.platform.is('android') || this.platform.is('capacitor')) {
            return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=3,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {});
        } else {
            return this.httpClient.get('https://www.punjabkingsipl.in/api/listing?entities=3,4&otherent=&pgnum=1&inum=10&pgsize=10').toPromise();
        }
    }

    getVideoDetails(title_alias_from_listing_api: string) {
        if (this.platform.is('android') || this.platform.is('capacitor')) {
            return this.http.get('https://www.punjabkingsipl.in/api/video/' + title_alias_from_listing_api, {}, {});
        } else {
            return this.httpClient.get('https://www.punjabkingsipl.in/api/video/' + title_alias_from_listing_api).toPromise();
        }
    }

    getGalleries() {
        if (this.platform.is('android') || this.platform.is('capacitor')) {
            return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=2,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {});
        } else {
            return this.httpClient.get('https://www.punjabkingsipl.in/api/listing?entities=2,4&otherent=&pgnum=1&inum=10&pgsize=10').toPromise();
        }
    }

    getGalleryDetails(title_alias_from_listing_api: string) {
        if (this.platform.is('android') || this.platform.is('capacitor')) {
            return this.http.get('https://www.punjabkingsipl.in/api/photo/' + title_alias_from_listing_api, {}, {});
        } else {
            return this.httpClient.get('https://www.punjabkingsipl.in/api/photo/' + title_alias_from_listing_api).toPromise();
        }
    }
}
