import{o as e}from"./chunk-mlkTr37E.js";import{t}from"./model-m-alveFP.js";import{r as n}from"./render-ju_tzmp-.js";import{t as r}from"./moment-BMP7hRUy.js";var i=e(n()),a=new t(`shopee_spy_list`),o=new t(`shopee_spy_log`);a.createIndex({index:{fields:[`type`,`shopId`,`productId`]}}),o.createIndex({index:{fields:[`id`,`date`,`type`]}});var s=e=>{if(e.shop_id&&e.item_id){let t=e;return{type:`product`,productId:e.item_id,shopId:e.shop_id,shopName:t.shop_data.account.username,shopMall:t.shop_data.is_official_shop,name:t.name,time:i.default.toDate(t.ctime),location:t.shop_data.shop_location,image:t.image,price:t.price,promotion:t.price,discount:0,stock:0,countRating:t.total_rating_count,countLike:t.liked_count,countView:t.view_count,sold:t.global_sold,sale:t.global_sold*t.price,variation:t.models.length,soldStart:t.global_sold,soldInc:0,url:``}}return{type:`shop`,name:e.name}},c=e=>e.shop_id&&e.item_id?[`product`,e.shop_id,e.item_id].join(`-`):[`shop`,e.shop_id].join(`-`),l=e=>a.insert(s(e),c(e)),u=async(e,t)=>{if(e.type===`product`){let n=t,i={sold:n.global_sold,sale:n.global_sold*n.price,soldInc:n.global_sold-e.soldStart},s={date:r(new Date),id:e._id,type:`product-sold`};return(await o.findMany(s)).length||await o.insert({...s,...i}),a.updateId(e._id,i)}return null};export{c as a,u as i,o as n,l as r,a as t};