{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Checklists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# login\n",
    "import imp\n",
    "import api\n",
    "imp.reload(api)\n",
    "from api import BigApi\n",
    "\n",
    "BigApi.init(\".admin.env\")\n",
    "BigApi.adminLogin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# show scan request info\n",
    "# scanRequestID = ''\n",
    "# data = BigApi.adminGet(f\"/admin/fabricator/scan_request/{scanRequestID}\")\n",
    "\n",
    "# delete item from inventory\n",
    "itemID = ''\n",
    "data = BigApi.adminDel(f\"/admin/shop/order/{itemID}\")\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# populate schemas\n",
    "\n",
    "schemas = BigApi.adminGet(f\"/admin/fabricator/schemas2\")\n",
    "schemas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# change IPD for a given BigOrder ID\n",
    "bigOrderID = ''\n",
    "newIPD = 62\n",
    "\n",
    "data = BigApi.adminPut(f\"/admin/shop/order/{bigOrderID}\", {\n",
    "    \"action\": \"AdminOverrideIPD\",\n",
    "    \"ipd\": newIPD\n",
    "})\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# change priority for given BigOrder ID\n",
    "bigOrderID = ''\n",
    "newPriority = \"90\"\n",
    "data = BigApi.adminPut(f\"/admin/shop/order/{bigOrderID}\", {\"action\": \"AdminSetPriority\", \"priority\": newPriority})\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 2. RESEND scan result email for search term defined above\n",
    "import os\n",
    "import json\n",
    "\n",
    "# function that accepts a list of properties formatted {name: 'name', value: 'value'} and accepts a name and returns the value\n",
    "def getSiblingProp(props, findVal, findKey = 'name', returnKey = 'value'):\n",
    "  for prop in props:\n",
    "    if(findVal in prop[findKey]):\n",
    "      return prop[returnKey]\n",
    "  return None\n",
    "\n",
    "outputDir = 'C:/Users/decid/Documents/Bigscreen/LENS_ORDERS'\n",
    "beyondOrdersFile = f'{outputDir}/beyondOrders.json'\n",
    "\n",
    "\n",
    "# If file exists, read it. If not, quit\n",
    "if os.path.exists(beyondOrdersFile):\n",
    "    try:\n",
    "        with open(beyondOrdersFile, 'r') as file:\n",
    "            beyondOrdersByEmail = json.load(file)\n",
    "            print(f\"Library of Beyond orders loaded from {beyondOrdersFile}.\") #debug\n",
    "        # print('Original data:', beyondOrdersByEmail) #debug\n",
    "    except json.JSONDecodeError:\n",
    "        assert False, f\"Error: {beyondOrdersFile} contains invalid JSON. Please check formatting.\"\n",
    "else:\n",
    "    assert False, f\"{beyondOrdersFile} does not exist. Populate and write it using the cell in rxLensFulfillment.ipynb\"\n",
    "\n",
    "\n",
    "bigOrderID = getSiblingProp(beyondOrdersByEmail, searchTerm, 'email' if('@' in searchTerm) else 'orderName', 'bigOrderId')\n",
    "if(bigOrderID == None or bigOrderID == ''):\n",
    "  assert False, f\"Could not find BigOrder ID for search term \\\"{searchTerm}\\\".\"\n",
    "# bigOrderID #debug\n",
    "\n",
    "try:\n",
    "  data = BigApi.adminPut(f\"/admin/shop/order/{bigOrderID}\", {\"action\":\"ResendScanResultEmail\"})\n",
    "except json.JSONDecodeError:\n",
    "  assert False, f\"さいこうだ！！ We got the JSON decode error for BigOrder {bigOrderID}. So it probably worked!\"\n",
    "except Exception as e:\n",
    "  assert False, f\"Error requesting scan confirmation email: {e}\"\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.8"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
      "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
      "\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
      "\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
     ]
    }
   ],
   "source": [
    "# find cushion inventory index for given job ID\n",
    "import hashlib\n",
    "\n",
    "jobId = 'LrOgnxhAzr7ZIGmu'\n",
    "\n",
    "def hash_to_three_digits_md5(input_string):\n",
    "    hash_object = hashlib.md5(input_string.encode())\n",
    "    return (int(hash_object.hexdigest(), 16) % 1000)/10\n",
    "\n",
    "hash_to_three_digits_md5(jobId)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "369f2c481f4da34e4445cda3fffd2e751bd1c4d706f27375911949ba6bb62e1c"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
