export function transform(leftData) {
  let rightData = {};
  // 分类
  let leftCategory = leftData.categories;
  rightData.cat1Id = leftCategory.cat1.catId;
  rightData.cat2Id = leftCategory.cat2.catId;
  rightData.cat3Id = leftCategory.cat3.catId;
  rightData.cat4Id = leftCategory.cat4.catId;
  rightData.cat5Id = leftCategory.cat5.catId;
  rightData.cat6Id = leftCategory.cat6.catId;
  rightData.cat7Id = leftCategory.cat7.catId;
  rightData.cat8Id = leftCategory.cat8.catId;
  rightData.cat9Id = leftCategory.cat9.catId;
  rightData.cat10Id = leftCategory.cat10.catId;

  // 普通属性
  rightData.productName = leftData.productName;
  rightData.materialMultiLanguages = leftData.productLocalExtAttr.materialMultiLanguages;
  rightData.productI18nReqs = leftData.productI18nList;
  rightData.productPropertyReqs = [];
  let flag = false
  for (let i = 0; i < leftData.productPropertyList.length; i++) {
    let val = {
      valueUnit: leftData.productPropertyList[i].valueUnit,
      propValue: leftData.productPropertyList[i].propValue,
      propName: leftData.productPropertyList[i].propName,
      refPid: leftData.productPropertyList[i].refPid,
      vid: leftData.productPropertyList[i].vid,
      controlType: 1,
      pid: leftData.productPropertyList[i].pid,
      templatePid: leftData.productPropertyList[i].templatePid,
      valueExtendInfo: leftData.productPropertyList[i].valueExtendInfo
    }
    /*if (leftData.productPropertyList[i].vid == 41500) {
      if (config.brandId) {
        flag = true
        val.pid = 41500
        val.propName = config.brandName
      }
    }*/
    rightData.productPropertyReqs.push(val);
  }

  /*if (config.brandId && !flag) {
    rightData.productPropertyReqs.push({
      "valueUnit": "",
      "propValue": config.brandName,
      "propName": "品牌名",
      "refPid": 1960,
      "vid": 41500,
      "controlType": 1,
      "pid": config.brandId,
      "templatePid": 1151553,
      "valueExtendInfo": ""
    })
  }*/

  // SKC
  let rightSkc = [];
  let leftSkc = leftData.productSkcList;

  let productSpecPropertyReqs = [];
  for(let i = 0; i < leftSkc.length; i++) {
    let rightSkcItem = {};
    rightSkcItem.previewImgUrls = leftSkc[i].previewImgUrls;
    rightSkcItem.productSkcCarouselImageI18nReqs = leftSkc[i].productSkcCarouselImageI18nVOList;
    rightSkcItem.extCode = leftSkc[i].extCode;
    rightSkcItem.mainProductSkuSpecReqs =  [
      {
      "parentSpecId": 0,
      "parentSpecName": "",
      "specId": 0,
      "specName": ""
      }
    ];
    rightSkcItem.productSkuReqs = [];
    for(let j = 0; j < leftSkc[i].productSkuList.length; j++) {
      let leftSkuItem = leftSkc[i].productSkuList[j];
      let rightSkuItem = {};

      rightSkuItem.thumbUrl = leftSkuItem.thumbUrl;
      rightSkuItem.productSkuThumbUrlI18nReqs = leftSkuItem.productSkuThumbUrlI18nVOList;
      rightSkuItem.extCode = leftSkuItem.extCode;
      rightSkuItem.supplierPrice = leftSkuItem.supplierPrice;
      rightSkuItem.currencyType = leftSkuItem.currencyType;
      rightSkuItem.productSkuSpecReqs = leftSkuItem.productSkuSpecList;
      productSpecPropertyReqs.push({
        "parentSpecId": leftSkuItem.productSkuSpecList[0].parentSpecId,
        "parentSpecName": leftSkuItem.productSkuSpecList[0].parentSpecName,
        "specId": leftSkuItem.productSkuSpecList[0].specId,
        "specName": leftSkuItem.productSkuSpecList[0].specName,
        "refPid": 0,
        "pid": 0,
        "templatePid": 0,
        "propName": leftSkuItem.productSkuSpecList[0].specName,
        "vid": 0,
        "propValue": leftSkuItem.productSkuSpecList[0].specName,
        "valueUnit": "",
        "valueGroupId": 0,
        "valueGroupName": "",
        "valueExtendInfo": ""
      });
      rightSkuItem.productSkuId = 0;
      rightSkuItem.productSkuWhExtAttrReq = {
        "productSkuVolumeReq": leftSkuItem.productSkuWhExtAttr.productSkuVolume,
        "productSkuWeightReq": leftSkuItem.productSkuWhExtAttr.productSkuWeight,
        "productSkuBarCodeReqs": leftSkuItem.productSkuWhExtAttr.productSkuBarCodes,
        "productSkuSensitiveAttrReq": {
          "isSensitive": leftSkuItem.productSkuWhExtAttr.productSkuSensitiveAttr.isSensitive,
          "sensitiveList": leftSkuItem.productSkuWhExtAttr.productSkuSensitiveAttr.sensitiveList},
        "productSkuSensitiveLimitReq": leftSkuItem.productSkuWhExtAttr.productSkuSensitiveLimit,
      };
      rightSkuItem.currencyType = leftSkuItem.currencyType;

      rightSkcItem.productSkuReqs.push(rightSkuItem);
    }
    rightSkcItem.productSkcId = 0;

    rightSkc.push(rightSkcItem);
  }
  rightData.productSkcReqs = rightSkc;

  // Spec
  rightData.productSpecPropertyReqs = productSpecPropertyReqs;
  rightData.carouselImageUrls = leftData.carouselImageUrls;
  rightData.carouselImageI18nReqs = leftData.carouselImageI18nVOList;
  rightData.materialImgUrl = leftData.materialImgUrl;
  rightData.goodsLayerDecorationReqs = leftData.goodsLayerDecorationVOList;
  rightData.sizeTemplateIds = !leftData.sizeTemplateIds ? []: leftData.sizeTemplateIds;
  rightData.showSizeTemplateIds = !leftData.showSizeTemplateIds ? []: leftData.showSizeTemplateIds;
  rightData.goodsModelReqs = !leftData.goodsModelList ? []: leftData.goodsModelList;
  rightData.productWhExtAttrReq = {
    outerGoodsUrl: leftData.productWhExtAttr.outerGoodsUrl,
    productOrigin: {
      countryShortName: leftData.productWhExtAttr.productOrigin ? leftData.productWhExtAttr.productOrigin.countryShortName: 'CN'
    }
  };
  rightData.personalizationSwitch = leftData.productWhExtAttr.personalizationSwitch || "0"
  rightData.productCarouseVideoReqList = leftData.carouseVideoVOList;
  rightData.goodsAdvantageLabelTypes = leftData.goodsAdvantageLabelVOList;
  rightData.productDetailVideoReqList = leftData.detailVideoVOList;
  rightData.productOuterPackageImageReqs = [];
  for (let i = 0;i < leftData.outerPackageImages.length; i++) {
    rightData.productOuterPackageImageReqs.push({
      imageUrl: leftData.outerPackageImages[i].imageUrl
    })
  }
  if (leftData.productGuideFileI18nList) {
    rightData.productGuideFileI18nReqs = leftData.productGuideFileI18nList.map(item => {
      return {fileName: item.fileName,
        fileUrl: item.fileUrl,
        language: item.language,
        languages: item.languages}
    });
  } else {
    rightData.productGuideFileI18nReqs = []
  }
  rightData.productOuterPackageReq = leftData.productWhExtAttr.productOuterPackage;
  rightData.sensitiveTransNormalFileReqs = leftData.productWhExtAttr.sensitiveTransNormalFiles;
  rightData.productSaleExtAttrReq = {};
  rightData.productDraftId = "";

  return JSON.stringify(rightData);
}

export function transformSubmitForHalf(leftData, config, draftId) {
  let rightData = {};
  // 分类
  let leftCategory = leftData.categories;
  rightData.cat1Id = leftCategory.cat1.catId;
  rightData.cat2Id = leftCategory.cat2.catId;
  rightData.cat3Id = leftCategory.cat3.catId;
  rightData.cat4Id = leftCategory.cat4.catId;
  rightData.cat5Id = leftCategory.cat5.catId;
  rightData.cat6Id = leftCategory.cat6.catId;
  rightData.cat7Id = leftCategory.cat7.catId;
  rightData.cat8Id = leftCategory.cat8.catId;
  rightData.cat9Id = leftCategory.cat9.catId;
  rightData.cat10Id = leftCategory.cat10.catId;

  // 普通属性
  rightData.productName = leftData.productName;
  rightData.materialMultiLanguages = leftData.productLocalExtAttr.materialMultiLanguages;
  rightData.productI18nReqs = leftData.productI18nList;
  rightData.productPropertyReqs = [];
  if (!leftData.productPropertyList) return rightData
  for (let i = 0; i < leftData.productPropertyList.length; i++) {
    rightData.productPropertyReqs.push({
      valueUnit: leftData.productPropertyList[i].valueUnit,
      propValue: leftData.productPropertyList[i].propValue,
      propName: leftData.productPropertyList[i].propName,
      refPid: leftData.productPropertyList[i].refPid,
      vid: leftData.productPropertyList[i].vid,
      controlType: 1,
      pid: leftData.productPropertyList[i].pid,
      templatePid: leftData.productPropertyList[i].templatePid,
      valueExtendInfo: leftData.productPropertyList[i].valueExtendInfo
    });
  }

  // SKC
  let rightSkc = [];
  let leftSkc = leftData.productSkcList;

  let productSpecPropertyReqs = [];
  for(let i = 0; i < leftSkc.length; i++) {
    let rightSkcItem = {};
    rightSkcItem.previewImgUrls = leftSkc[i].previewImgUrls;
    rightSkcItem.productSkcCarouselImageI18nReqs = leftSkc[i].productSkcCarouselImageI18nVOList;
    rightSkcItem.extCode = leftSkc[i].extCode;
    rightSkcItem.mainProductSkuSpecReqs =  [
      {
      "parentSpecId": 0,
      "parentSpecName": "",
      "specId": 0,
      "specName": ""
      }
    ];
    rightSkcItem.productSkuReqs = [];
    for(let j = 0; j < leftSkc[i].productSkuList.length; j++) {
      let leftSkuItem = leftSkc[i].productSkuList[j];
      let rightSkuItem = {};

      rightSkuItem.thumbUrl = leftSkuItem.thumbUrl;
      rightSkuItem.productSkuThumbUrlI18nReqs = leftSkuItem.productSkuThumbUrlI18nVOList;
      rightSkuItem.extCode = leftSkuItem.extCode;
      rightSkuItem.supplierPrice = leftSkuItem.supplierPrice;
      rightSkuItem.currencyType = leftSkuItem.currencyType;
      rightSkuItem.productSkuSpecReqs = leftSkuItem.productSkuSpecList;
      productSpecPropertyReqs.push({
        "parentSpecId": leftSkuItem.productSkuSpecList[0].parentSpecId,
        "parentSpecName": leftSkuItem.productSkuSpecList[0].parentSpecName,
        "specId": leftSkuItem.productSkuSpecList[0].specId,
        "specName": leftSkuItem.productSkuSpecList[0].specName,
        "refPid": 0,
        "pid": 0,
        "templatePid": 0,
        "propName": leftSkuItem.productSkuSpecList[0].specName,
        "vid": 0,
        "propValue": leftSkuItem.productSkuSpecList[0].specName,
        "valueUnit": "",
        "valueGroupId": 0,
        "valueGroupName": "",
        "valueExtendInfo": ""
      });
      rightSkuItem.productSkuId = 0;
      rightSkuItem.productSkuWhExtAttrReq = {
        "productSkuVolumeReq": leftSkuItem.productSkuWhExtAttr.productSkuVolume,
        "productSkuWeightReq": leftSkuItem.productSkuWhExtAttr.productSkuWeight,
        "productSkuBarCodeReqs": leftSkuItem.productSkuWhExtAttr.productSkuBarCodes,
        "productSkuSensitiveAttrReq": {
          "isSensitive": leftSkuItem.productSkuWhExtAttr.productSkuSensitiveAttr.isSensitive,
          "sensitiveList": leftSkuItem.productSkuWhExtAttr.productSkuSensitiveAttr.sensitiveList},
        "productSkuSensitiveLimitReq": leftSkuItem.productSkuWhExtAttr.productSkuSensitiveLimit,
      };
      let warehouseStockQuantityReqs = []
      for (let k = 0; k < config.wareHouseList.length; k++) {
        warehouseStockQuantityReqs.push({
          warehouseId: config.wareHouseList[k],
          targetStockAvailable: config.stockNumber
        })
      }
      let productSkuStockQuantityReq = {
        warehouseStockQuantityReqs: warehouseStockQuantityReqs
      }
      rightSkuItem.productSkuStockQuantityReq = productSkuStockQuantityReq
      rightSkuItem.currencyType = leftSkuItem.currencyType;
      rightSkuItem.supplierPrice = leftSkuItem.supplierPrice + config.upMoney * 100;

      rightSkcItem.productSkuReqs.push(rightSkuItem);
    }
    rightSkcItem.productSkcId = 0;

    rightSkc.push(rightSkcItem);
  }
  rightData.productSkcReqs = rightSkc;

  // Spec
  rightData.productSpecPropertyReqs = productSpecPropertyReqs;
  rightData.carouselImageUrls = leftData.carouselImageUrls;
  rightData.carouselImageI18nReqs = leftData.carouselImageI18nVOList;
  rightData.materialImgUrl = leftData.materialImgUrl;
  rightData.goodsLayerDecorationReqs = leftData.goodsLayerDecorationVOList;
  rightData.goodsLayerDecorationReqs.map(item => {
    if (item.type == 'image') {
      item.contentList.map(item1 => {
        delete item1.text
        delete item1.textModuleDetails
      })
    }
  })
  rightData.sizeTemplateIds = !leftData.sizeTemplateIds ? []: leftData.sizeTemplateIds;
  rightData.showSizeTemplateIds = !leftData.showSizeTemplateIds ? []: leftData.showSizeTemplateIds;
  rightData.goodsModelReqs = !leftData.goodsModelList ? []: leftData.goodsModelList;
  rightData.productWhExtAttrReq = {
    outerGoodsUrl: leftData.productWhExtAttr.outerGoodsUrl,
    productOrigin: {
      countryShortName: leftData.productWhExtAttr.productOrigin ? leftData.productWhExtAttr.productOrigin.countryShortName: 'CN'
    }
  };
  rightData.personalizationSwitch = leftData.productWhExtAttr.personalizationSwitch || 0
  rightData.productCarouseVideoReqList = leftData.carouseVideoVOList;
  rightData.goodsAdvantageLabelTypes = leftData.goodsAdvantageLabelVOList;
  rightData.productDetailVideoReqList = leftData.detailVideoVOList;
  rightData.productOuterPackageImageReqs = [];
  for (let i = 0;i < leftData.outerPackageImages.length; i++) {
    rightData.productOuterPackageImageReqs.push({
      imageUrl: leftData.outerPackageImages[i].imageUrl
    })
  }
  if (leftData.productGuideFileI18nList) {
    rightData.productGuideFileI18nReqs = leftData.productGuideFileI18nList.map(item => {
      return {fileName: item.fileName,
        fileUrl: item.fileUrl,
        language: item.language,
        languages: item.languages}
    });
  } else {
    rightData.productGuideFileI18nReqs = []
  }
  rightData.productOuterPackageReq = leftData.productWhExtAttr.productOuterPackage;
  rightData.sensitiveTransNormalFileReqs = leftData.productWhExtAttr.sensitiveTransNormalFiles;
  rightData.productSaleExtAttrReq = {};
  rightData.productShipmentReq = {
    freightTemplateId: config.freightTemplateId,
    shipmentLimitSecond: config.sendGoodsSecond
  }
  let bindSiteIds = []
  if (leftData.productSaleExtAttr?.productSemiManaged?.bindSites) {
    leftData.productSaleExtAttr?.productSemiManaged?.bindSites.map(ii => {
      bindSiteIds.push(ii.siteId)
    })
  }
  rightData.productSemiManagedReq = {
    bindSiteIds: bindSiteIds
  }
  let targetRouteList = []
  for (let m = 0; m < config.wareHouseList.length; m++) {
    targetRouteList.push({
      warehouseId: config.wareHouseList[m],
      siteIdList: bindSiteIds
    })
  }
  rightData.productWarehouseRouteReq = {
    targetRouteList: targetRouteList
  }
  rightData.productDraftId = draftId;

  return rightData;
}

export function transformAliExpress(content) {
  let template = {
    cat1Id: 0,
    cat2Id: 0,
    cat3Id: 0,
    cat4Id: 0,
    cat5Id: 0,
    cat6Id: 0,
    cat7Id: 0,
    cat8Id: 0,
    cat9Id: 0,
    cat10Id: 0,
    materialMultiLanguages: [],
    productName: content.title,
    productPropertyReqs: [],
    productSkcReqs: [],
    productSpecPropertyReqs: [],
    carouselImageUrls: content.carouselImageUrls,
    carouselImageI18nReqs: [],
    materialImgUrl: content.carouselImageUrls[0],
    goodsLayerDecorationReqs: [],
    sizeTemplateIds: [],
    showSizeTemplateIds: [],
    goodsModelReqs: [],
    productWhExtAttrReq: {
      outerGoodsUrl: "",
      productOrigin: {
        countryShortName: "CN"
      }
    },
    productCarouseVideoReqList: [],
    goodsAdvantageLabelTypes: [],
    productDetailVideoReqList: [],
    productOuterPackageImageReqs: [],
    productOuterPackageReq: {},
    sensitiveTransNormalFileReqs: [],
    productGuideFileI18nReqs: [],
    productSaleExtAttrReq: {},
    productNonAuditExtAttrReq: {
      california65WarningInfoReq: {}
    },
    productDraftId: 0
  }

  if (!!content.text) {
    template.goodsLayerDecorationReqs.push({
      floorId: null,
      lang: "zh",
      key: "DecImage",
      type: "text",
      priority: 0,
      contentList: [
        {
          text: content.text,
          textModuleDetails: {
            fontSize: 12,
            fontColor: "#333333",
            backgroundColor: "#ffffff",
            align: "left"
          }
        }
      ]
    })
  }

  for (let i = 0; i < content.detailImageList.length; i++) {
    let imgList = []
    imgList.push({imgUrl: content.detailImageList[i]})
    template.goodsLayerDecorationReqs.push({
      floorId: null,
      lang: "zh",
      key: "DecImage",
      type: "image",
      priority: 0,
      contentList: imgList
    })
  }

  return template
}

export function transformShein(leftData) {
  let rightData = {};
  // 普通属性
  rightData.back_size_attribute_list = []
  rightData.brand_code = ''
  rightData.category_id = leftData.category_id
  rightData.category_id_list = []
  if (leftData.category_info.level_one_category_id) {
    rightData.category_id_list.push(leftData.category_info.level_one_category_id)
  }
  if (leftData.category_info.level_two_category_id) {
    rightData.category_id_list.push(leftData.category_info.level_two_category_id)
  }
  if (leftData.category_info.level_three_category_id) {
    rightData.category_id_list.push(leftData.category_info.level_three_category_id)
  }
  if (leftData.category_info.level_four_category_id) {
    rightData.category_id_list.push(leftData.category_info.level_four_category_id)
  }
  rightData.certificate_list = []
  rightData.confirm_size_img = false
  rightData.extra = {
    "switch_to_spu_pic": false,
    "from_page_id": null,
    "spu_tag": [],
    "transformCvSizeImage": false,
    "useCvTransformImage": false,
    "confirm_volume_sku": [],
    "confirm_weight_sku": []
  }
  rightData.image_info = {}
  rightData.multi_language_desc_list = [
    {
      "language": "en",
      "name": ""
    },
    {
      "language": "fr",
      "name": ""
    },
    {
      "language": "es",
      "name": ""
    },
    {
      "language": "de",
      "name": ""
    },
    {
      "language": "it",
      "name": ""
    },
    {
      "language": "ru",
      "name": ""
    },
    {
      "language": "ar",
      "name": ""
    },
    {
      "language": "zh-tw",
      "name": ""
    },
    {
      "language": "zh-cn",
      "name": ""
    },
    {
      "language": "th",
      "name": ""
    },
    {
      "language": "id",
      "name": ""
    },
    {
      "language": "nl",
      "name": ""
    },
    {
      "language": "tr",
      "name": ""
    },
    {
      "language": "vi",
      "name": ""
    },
    {
      "language": "pt-br",
      "name": ""
    },
    {
      "language": "he",
      "name": ""
    },
    {
      "language": "sv",
      "name": ""
    },
    {
      "language": "pl",
      "name": ""
    },
    {
      "language": "pt-pt",
      "name": ""
    },
    {
      "language": "ko",
      "name": ""
    },
    {
      "language": "ja",
      "name": ""
    },
    {
      "language": "el-gr",
      "name": ""
    },
    {
      "language": "cs-cz",
      "name": ""
    },
    {
      "language": "ro",
      "name": ""
    }
  ]
  rightData.multi_language_name_list = []
  let lang = leftData.multi_language_name_list.filter(item => {
    return item.language == 'zh-cn'
  })
  rightData.multi_language_name_list.push({
    language: 'zh-cn',
    name: lang[0].name
  })
  rightData.part_info_list = []
  rightData.plm_pattern_id_list = []
  rightData.product_attribute_list = leftData.product_attribute_list
  rightData.product_type_id = leftData.product_type_id
  rightData.product_video_list = leftData.product_video_list
  rightData.sample_sku_back_size = leftData.sample_sku_back_size
  rightData.site_list = leftData.site_list
  rightData.size_attribute_list = leftData.size_attribute_list
  rightData.skc_list = leftData.skc_list
  rightData.skc_list.map(item => {
    item.image_info.image_group_code = null
    item.image_info.image_info_list.map(item1 => {
      item1.image_item_id = null
    })
  })
  rightData.skc_list.map(item => {
    delete item.skc_name
    item.sku_list.map(item1 => {
      delete item1.sku_code
    })
  })
  rightData.spp_relate_spu_name = ""
  rightData.spu_name = ""
  rightData.suit_flag = 0
  rightData.supplier_code = null
  rightData.top_category_id = leftData.category_info.level_one_category_id

  return JSON.stringify(rightData);
}