// export const SHOPTIME_BASE_URL = "https://qt2-aic.lgshopsvc.lgappstv.com/";
export const SHOPTIME_BASE_URL = ".lgshopsvc.lgappstv.com";

export const URLS = {
  //device controller
  GET_AUTHENTICATION_CODE: "/lgsp/v1/device/auth.lge",
  GET_RE_AUTHENTICATION_CODE: "/lgsp/v1/device/reauth.lge",
  GET_DEVICE_ADDITION_INFO: "/lgsp/v1/device/info/addition.lge",
  DELETE_DEVICE_ADDITION_INFO: "/lgsp/v1/device/info/addition/delete.lge",
  DELETE_DEVICE_PAIRING: "/lgsp/v1/device/pairing/delete.lge",
  REGISTER_DEVICE_PAIRING: "/lgsp/v1/device/pairing/register.lge",
  REGISTER_DEVICE: "/lgsp/v1/device/register.lge",
  REGISTER_DEVICE_INFO: "/lgsp/v1/device/register/info.lge",
  GET_DEVICE_INFO: "/lgsp/v1/device/info/addition.lge",

  // billing controller
  GET_MY_INFO_BILLING_SEARCH: "/lgsp/v1/myinfo/address/billing/search.lge",

  // card controller
  GET_MY_INFO_CARD_SEARCH: "/lgsp/v1/myinfo/card/search.lge",

  // shipping controller
  GET_MY_INFO_SHIPPING_SEARCH: "/lgsp/v1/myinfo/address/shipping/search.lge",

  //home controller
  GET_HOME_TERMS: "/lgsp/v1/home/terms.lge",
  GET_HOME_MENU: "/lgsp/v1/home/menu.lge",
  GET_HOME_LAYOUT: "/lgsp/v1/home/homeLayout.lge",
  GET_HOME_MAIN_CONTENTS: "/lgsp/v1/home/homeContentsInfo.lge",
  GET_THEME_CURATION_INFO: "/lgsp/v2/home/theme/curations.lge",
  GET_THEME_CURATION_DETAIL_INFO: "/lgsp/v1/home/theme/curation/detail.lge",
  GET_THEME_HOTEL_DETAIL_INFO: "/lgsp/v1/home/theme/hotel/detail.lge",
  GET_THEME_MENU_SHELF_INFO: "/lgsp/v1/home/theme/menu/shelf/info.lge",

  //brand-controller
  GET_BRAND_LIST: "/lgsp/v1/brand/info.lge",
  GET_BRAND_LAYOUT_INFO: "/lgsp/v1/brand/shelf.lge",
  GET_BRAND_LIVE_CHANNEL_INFO: "/lgsp/v1/brand/live.lge",
  GET_BRAND_TSV_INFO: "/lgsp/v1/brand/tsv.lge",
  GET_BRAND_RECOMMENDED_SHOW_INFO: "/lgsp/v1/brand/recommend.lge",
  GET_BRAND_SERIES_INFO: "/lgsp/v1/brand/series.lge",
  GET_BRAND_CATEGORY_INFO: "/lgsp/v1/brand/category.lge",
  GET_BRAND_BEST_SELLER: "/lgsp/v1/brand/bestSeller.lge",
  GET_BRAND_CREATORS_INFO: "/lgsp/v1/brand/creators.lge",
  GET_BRAND_SHOWROOM: "/lgsp/v1/brand/showroom.lge",
  GET_BRAND_RECENTLY_AIRED: "/lgsp/v1/brand/recently/aired.lge",

  //on-sale controller
  GET_ON_SALE_INFO: "/lgsp/v1/onsale/onsale.lge",

  //product controller
  GET_PRODUCT_BESTSELLER: "/lgsp/v1/product/bestSeller.lge",
  GET_PRODUCT_GROUP: "/lgsp/v1/product/group.lge",
  GET_PRODUCT_OPTION: "/lgsp/v1/product/option.lge",

  //my-page controller
  GET_MY_RECOMMANDED_KEYWORD: "/lgsp/v1/mypage/reckeyword.lge",
  GET_MY_FAQ_INFO: "/lgsp/v1/mypage/support/faq.lge",
  GET_NOTICE: "/lgsp/v1/mypage/support/notice.lge",
  GET_MY_CUSTOMERS: "/lgsp/v1/mypage/customers.lge",
  GET_MY_FAVORITE: "/lgsp/v1/mypage/favorite.lge",
  DELETE_MY_FAVORITE: "/lgsp/v1/mypage/favorite.lge",
  GET_MY_FAVORITE_FLAG: "/lgsp/v1/mypage/favorite/flag.lge",
  SET_MY_TERMS_WITHDRAW: "/lgsp/v1/mypage/terms/withdraw.lge",
  GET_MY_UPCOMING_CHANGE_INFO: "/lgsp/v1/mypage/upcoming/alert/changeinfo.lge",
  GET_MY_UPCOMING_ALERT_SHOW: "/lgsp/v1/mypage/upcoming/alert/show.lge",
  DELETE_MY_UPCOMING_ALERT_SHOW: "/lgsp/v1/mypage/upcoming/alert/show.lge",
  GET_MY_UPCOMING_ALERT_SHOW_KEYS:
    "/lgsp/v1/mypage/upcoming/alert/show/keys.lge",
  SET_MY_UPCOMING_USE_ALERT: "/lgsp/v1/mypage/upcoming/alert/use.lge",
  GET_UPCOMING_ALERT_SHOW_CHANGE_INFO:
    "/lgsp/v1/mypage/upcoming/show/changeinfo.lge",
  GET_MY_RECENTLY_VIEWED_INFO: "/lgsp/v1/mypage/recently/viewed.lge",

  //search controller
  GET_SEARCH: "/lgsp/v1/search/list.lge",

  //main controller
  GET_SUB_CATEGORY: "/lgsp/v1/main/subcategory.lge",
  GET_TOP20_SHOW: "/lgsp/v1/main/top/show.lge",
  GET_PRODUCT_DETAIL: "/lgsp/v1/main/category/product/detail.lge",
  GET_YOUMAYLIKE: "/lgsp/v1/main/youmaylike.lge",
  GET_HOME_FULL_VIDEO_INFO: "/lgsp/v1/main/homeFullVideoInfo.lge",
  SET_MAIN_LIKE_CATEGORY: "/lgsp/v1/main/category/like.lge",
  SET_MAIN_LIVE_UPCOMING_ALARM: "/lgsp/v1/main/live/upcoming/alarm.lge",
  GET_MAIN_LIVE_SHOW_NOW_PRODUCT: "/lgsp/v1/main/live/show/nowproduct.lge",
  GET_MAIN_CATEGORY_SHOW_DETAIL: "/lgsp/v1/main/category/show/detail.lge",
  GET_MAIN_LIVE_SHOW: "/lgsp/v1/main/live/show.lge",

  //event controller
  GET_WELCOME_EVENT_INFO: "/lgsp/v1/event/event.lge",
  GET_EVENT_ISSUED_STATUS: "/lgsp/v1/event/issued/status.lge",
  SET_EVENT_ISSUE_REQ: "/lgsp/v1/event/issued.lge",
  SET_EVENT_POP_CLICK_INFO: "/lgsp/v1/event/popup/click.lge",

  // coupon actions
  GET_PRODUCT_COUPON_INFO: "/lgsp/v1/product/coupon/info.lge",
  GET_PRODUCT_COUPON_SEARCH: "/lgsp/v1/product/coupon/search.lge",
  GET_PRODUCT_COUPON_DOWNLOAD: "/lgsp/v1/product/coupon/download.lge",
  GET_PRODUCT_COUPON_TOTDOWNLOAD: "/lgsp/v1/product/coupon/totDownload.lge",

  //checkout controller
  GET_CHECKOUT_INFO: "/lgsp/v1/myinfo/checkout/info.lge",
  INSERT_MY_INFO_CHECKOUT_ORDER: "/lgsp/v1/myinfo/checkout/order.lge",
  GET_TAX_INFOS: "/lgsp/v1/myinfo/checkout/taxInfo.lge",
  GET_CHECKOUT_TOTAL_AMT: "/lgsp/v1/myinfo/checkout/totalAmt.lge",

  // app controller
  SEND_SMS: "/lgsp/v1/app/sms.lge",

  // play controller
  CHAT_LOG: "/lgsp/v1/play/vod/chatLog.lge",
  SUBTITLE: "/lgsp/v1/play/vod/subtitle.lge",

  // order controller
  SET_PURCHASE_TERMS_AGREE: "/lgsp/v1/myinfo/purchaseTerms/agree.lge",
  SET_PURCHASE_TERMS_WITHDRAW: "/lgsp/v1/myinfo/purchaseTerms/withdraw.lge",
  GET_MY_INFO_ORDER_SEARCH: "/lgsp/v1/myinfo/order/info.lge",
  GET_MY_INFO_ORDER_DETAIL_SEARCH: "/lgsp/v1/myinfo/order/detail.lge",
  GET_MY_INFO_ORDER_SHIPPING_SEARCH: "/lgsp/v1/myinfo/order/shipping.lge",

  // cancel controller
  GET_MY_INFO_ORDER_CANCEL_SEARCH: "/lgsp/v1/myinfo/order/cancel/info.lge",
  GET_MY_INFO_ORDER_CANCEL_COLUMNS_SEARCH:
    "/lgsp/v1/myinfo/order/cancel/reasoninfo.lge",
  UPDATE_ORDER_PARTIAL_CANCEL: "/lgsp/v1/myinfo/order/orderPartialCancel.lge",
  PAYMENT_TOTAL_CANCEL: "/lgsp/v1/myinfo/order/paymentTotalCancel.lge",

  // emp controller
  GET_SHOPTIME_TERMS: "/lgsp/v1/emp/shoptime/terms.lge",
  SET_MYPAGE_TERMS_AGREE: "/lgsp/v1/mypage/terms/agree.lge",
  // pinCode controller
  GET_MY_INFO_CARD_PINCODE_CHECK: "/lgsp/v1/myinfo/card/pincode/check.lge",

  // log deeplink controller
  LOG_DEEPLINK: "/lgsp/v1/log/deeplink.lge",

  // IF-LGSP-LOG-001 log live controller
  LOG_LIVE: "/lgsp/v1/log/live.lge",

  // IF-LGSP-LOG-002 log vod controller
  LOG_VOD: "/lgsp/v1/log/vod.lge",

  // IF-LGSP-LOG-003 log curation controller
  LOG_CURATION: "/lgsp/v1/log/curation.lge",

  // IF-LGSP-LOG-004 log second layer controller
  LOG_SECOND_LAYER: "/lgsp/v1/log/secondlayer.lge",

  // IF-LGSP-LOG-005 log gnb controller
  LOG_GNB: "/lgsp/v1/log/gnb.lge",

  // IF-LGSP-LOG-006 log product controller
  LOG_PRODUCT: "/lgsp/v1/log/product.lge",

  // IF-LGSP-LOG-007 log detail controller
  LOG_DETAIL: "/lgsp/v1/log/detail.lge",

  // IF-LGSP-LOG-008 log shop by mobile controller
  LOG_SHOP_BY_MOBILE: "/lgsp/v1/log/shopbymobile.lge",

  // IF-LGSP-LOG-009 log partners controller
  LOG_PARTNERS: "/lgsp/v1/log/partners.lge",

  // IF-LGSP-LOG-010 log alert flag controller
  LOG_MY_PAGE_ALERT_FLAG: "/lgsp/v1/log/mypage/alertflag.lge",

  // IF-LGSP-LOG-011 log my delete controller
  LOG_MY_PAGE_MY_DELETE: "/lgsp/v1/log/mypage/mydelete.lge",

  // IF-LGSP-LOG-012 log notive controller
  LOG_MY_PAGE_NOTICE: "/lgsp/v1/log/mypage/notice.lge",

  // IF-LGSP-LOG-013 log search controller
  LOG_SEARCH: "/lgsp/v1/log/search/search.lge",

  // IF-LGSP-LOG-014 log search click controller
  LOG_SEARCH_CLICK: "/lgsp/v1/log/search/click.lge",

  // IF-LGSP-LOG-015 log upcoming flag controller
  LOG_UPCOMING_FLAG: "/lgsp/v1/log/upcoming/upcomingflag.lge",

  // IF-LGSP-LOG-016 log keyword flag controller, 미사용
  // LOG_KEYWORD_FLAG: "/lgsp/v1/log/upcoming/keywordflag.lge",

  // IF-LGSP-LOG-017 log alarm pop controller
  LOG_ALARM_POP: "/lgsp/v1/log/alarm/alarmpop.lge",

  // IF-LGSP-LOG-018 log alarm click controller
  LOG_ALARM_CLICK: "/lgsp/v1/log/alarm/alarmclick.lge",

  // IF-LGSP-LOG-019 검증 필요
  LOG_PURCHASE_TRACKING: "/lgsp/v1/log/purchase/tracking.lge",

  // IF-LGSP-LOG-020 log theme product controller
  LOG_THEME_PRODUCT: "/lgsp/v1/log/theme/product.lge",

  // IF-LGSP-LOG-100 log top contents controller
  LOG_TOP_CONTENTS: "/lgsp/v1/log/topcontents.lge",

  // IF-LGSP-LOG-101 log tearms controller
  LOG_TERMS: "/lgsp/v1/log/terms.lge",

  // IF-LGSP-LOG-102 log login controller
  LOG_ACCOUNT_LOGIN: "/lgsp/v1/log/account/login.lge",

  // IF-LGSP-LOG-103 log order btn click controller
  LOG_ORDER_BTN_CLICK: "/lgsp/v1/log/order/btnClick.lge",

  // IF-LGSP-LOG-104 log order change controller
  LOG_ORDER_CHANGE: "/lgsp/v1/log/order/change.lge",

  // IF-LGSP-LOG-105 log coupon use controller
  LOG_COUPON_USE: "/lgsp/v1/log/coupon/use.lge",

  // IF-LGSP-LOG-106 log cart add controller, 미사용
  // LOG_CART_ADD: "/lgsp/v1/log/cart/add.lge",

  // IF-LGSP-LOG-107 log cart delete controller, 미사용
  // LOG_CART_DELETE: "/lgsp/v1/log/cart/delete.lge",

  // IF-LGSP-LOG-108 log payment entry controller
  LOG_PAYMENT_ENTRY: "/lgsp/v1/log/payment/entry.lge",

  // IF-LGSP-LOG-109 log payment complete controller
  LOG_PAYMENT_COMPLETE: "/lgsp/v1/log/payment/complete.lge",

  // IF-LGSP-LOG-110 log brands controller
  LOG_BRANDS: "/lgsp/v1/log/brands.lge",

  // IF-LGSP-LOG-111 log myinfo controller
  LOG_MY_INFO_EDIT: "/lgsp/v1/log/myinfo/edit.lge",

  // IF-LGSP-LOG-112 log checkout btn click controller
  LOG_CHECKOUT_BTN_CLICK: "/lgsp/v1/log/checkout/btnClick.lge",

  // IF-LGSP-LOG-200
  LOG_TOTAL_RECOMMEND: "/lgsp/v1/log/recommend.lge",
};

export let countryCode = "";
export let ricCode = "";

const getRicCode = (country, ricCodeSetting) => {
  if (ricCodeSetting !== "system") {
    return ricCodeSetting;
  }
  if (country == "US") {
    return "aic";
  } else if (country == "DE" || country == "GB") {
    return "eic";
  } else if (country == "RU") {
    return "ruc";
  }
  return null;
};
export const getUrl = (getState, endStr) => {
  const serverHOST = getState().common.appStatus.serverHOST;
  const { serverType, ricCodeSetting } = getState().localSettings;
  if (!serverHOST) {
    console.error("getUrl: Not supported. Host is missing");
    return "";
  }
  // serverHOST "qt2-US.nextlgsdp.com"
  let sdpURL = serverHOST.split(".")[0];

  // let countryCode = "",
  // ricCode = "";
  if (sdpURL.indexOf("-") > 0) {
    countryCode = sdpURL.split("-")[1];
  } else {
    countryCode = sdpURL;
  }
  ricCode = getRicCode(countryCode, ricCodeSetting);
  if (!ricCode) {
    return "";
  }

  sdpURL = sdpURL.toLowerCase();
  if (serverType !== "system") {
    sdpURL = serverType;
  }
  let newUrl = "";
  if (sdpURL.indexOf("qt2") >= 0) {
    // dev
    newUrl = "https://qt2-" + ricCode + SHOPTIME_BASE_URL;
  } else if (sdpURL.indexOf("qt") >= 0 || sdpURL.indexOf("st") >= 0) {
    // Qa - cdn
    newUrl = "https://qt-" + ricCode + SHOPTIME_BASE_URL;
  } else {
    // Prod
    newUrl = "https://" + ricCode + SHOPTIME_BASE_URL;
  }
  return newUrl + endStr;
};
