import LS2Request from "./LS2Request";

export const getConnectionStatus = ({ onSuccess, onFailure, onComplete }) => {
  if (process.env.REACT_APP_MODE === "DEBUG") {
    console.log("LUNA SEND getConnectionStatus");
    return "Some Hard Coded Mock Data";
  } else {
    return new LS2Request().send({
      service: "luna://com.webos.service.connectionmanager",
      method: "getStatus",
      subscribe: true,
      parameters: {},
      onSuccess,
      onFailure,
      onComplete,
    });
  }
};

export const createToast = (message) => {
	if (typeof window === 'object' && !window.PalmSystem) {
    console.log("LUNA SEND createToast message", message);
		return;
	}
	return new LS2Request().send({
		service: 'luna://com.webos.notification',
		method: 'createToast',
		parameters:  {
			message: message,
			iconUrl: '',
			noaction: true
		},
		onSuccess: (res) => {
			console.log("LUNA SEND createToast success", message);
		},
		onFailure: (err) => {
			console.log("LUNA SEND createToast failed", err);
		}
	});
};

let httpHeaderHandler = null;
export const getHttpHeaderForServiceRequest = ({onSuccess, onFailure, onComplete}) => {
  if (typeof window === "object" && window.PalmSystem) {
    if (process.env.REACT_APP_MODE === "DEBUG") {
      console.log("LUNA SEND getHttpHeaderForServiceRequest");
      return "Some Hard Coded Mock Data";
    } else {
      if(httpHeaderHandler){
        httpHeaderHandler.cancel();
      }
      httpHeaderHandler = new LS2Request().send({
        service: "luna://com.webos.service.sdx",
        method: "getHttpHeaderForServiceRequest",
        subscribe: true,
        parameters: {},
        onSuccess,
        onFailure,
        onComplete,
      });
      return httpHeaderHandler;
    }
  }else{
    onSuccess({
		"HOST": "US.nextlgsdp.com",
		"Authorization": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJuZXh0bGdzZHAuY29tIiwiYXVkIjoibmV4dGxnc2RwLmNvbSIsImlhdCI6MTcwNzc4NTUyNSwiZXhwIjoxNzA3NzkyNzI1LCJtYWNBZGRyZXNzIjoiZWVkMDQ2NjdiNjUzOWU3YmQxMDA1OTljYjBkYTI5ZjRjZTgyZGZlOGZkNzIzMDAxZGVmMjg4NWRkNWZiODRmNWNiMzZlM2QwNzYzNWZjZGJjYWNjNGVjMzI5NWIwNjZjOTMwNmNmNDI1ZGQzMmQ2MDMxMjc1NWNkOTIyNjEwMzcifQ.vqPdYGnN46diesDBLzA4UhACCJVdIycLs7wZu9M55Hc",
		"X-Authentication": "MkOLvUocrJ69RH/iV1ZABJhjR2g=",
		"X-Device-ID": "OemUY5qbPITZv96QKlxrtcqT6ypeX6us2qANLng3/0QCUhv2mecK1UDTMYb/hjpjey9dC/kFycc/5R8u+oK56JIWyYC4V278z64YDPKbDXIsd+eECvyf+Rdm8BneIUPM",
		"X-Device-Product": "webOSTV 5.0",
		"X-Device-Platform": "W20P",
		"X-Device-Model": "HE_DTV_W20P_AFADATAA",
		"X-Device-Eco-Info": "1",
		"X-Device-Country": "US",
		"X-Device-Language":"en-US",
		"X-Device-Netcast-Platform-Version": "5.0.0",
		"X-Device-Publish-Flag": "N",
		"X-Device-Fck": "253",
		"X-Device-Eula": "additionalDataAllowed,takeOnAllowed,networkAllowed,generalTermsAllowed,chpAllowed,customAdAllowed,acrOnAllowed,voice2Allowed,voiceAllowed,acrAdAllowed"
	});
  }
};