"use strict";const e=require("../common/vendor.js");function t(t,o={}){const a=e.index.getStorageSync("token");let n="https://api.makesong.cn/yu"+t;if("GET"===(o.method||"GET")&&o.data){const e=[];Object.keys(o.data).forEach((t=>{const a=o.data[t];null!=a&&e.push(`${encodeURIComponent(t)}=${encodeURIComponent(String(a))}`)}));const t=e.join("&");t&&(n+="?"+t)}return new Promise(((t,i)=>{e.index.request({url:n,method:o.method||"GET",data:"GET"===(o.method||"GET")?void 0:o.data,header:{"Content-Type":"application/json",...a&&{Authorization:`Bearer ${a}`},...o.header},success:o=>{const a=o.data;200===a.code?t(a.data):401==a.code?(e.index.removeStorageSync("token"),e.index.reLaunch({url:"/pages/login/login"})):(e.index.showToast({title:a.message||"请求失败",icon:"none"}),i(new Error(a.message)))},fail:t=>{e.index.showToast({title:"网络请求失败",icon:"none"}),i(t)}})}))}const o={auth:{register:(e,o)=>t("/api/auth/register",{method:"POST",data:{phone:e,nickname:o}}),sendCode:e=>t("/api/auth/send-code",{method:"POST",data:{phone:e}}),verificationLogin:(e,o)=>t("/api/auth/verification-login",{method:"POST",data:{phone:e,code:o}}),oneClickLogin:e=>t("/api/auth/one-click-login",{method:"POST",data:{phone:e}})},user:{getProfile:()=>t("/api/users/profile"),updateProfile:e=>t("/api/users/profile",{method:"PUT",data:e})},timeslots:{getList:e=>t("/api/timeslots",{data:e}),getById:e=>t(`/api/timeslots/${e}`)},appointments:{getList:e=>t("/api/appointments",{data:e}),getById:e=>t(`/api/appointments/${e}`),create:(e,o=1,a)=>t("/api/appointments",{method:"POST",data:{time_slot_id:e,people_count:o,notes:a}}),cancel:e=>t(`/api/appointments/${e}`,{method:"DELETE"})},health:()=>t("/health")};exports.api=o;
