using BPA.SAAS.KitChenManage.Core;
using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto;
using BPA.SAAS.Manage.Application.AExternalPlatform.Enum;
using BPA.SAAS.Manage.Application.AExternalPlatform.Service.DiningPlate.Dtos;
using BPA.SAAS.Manage.Comm.Enum;
using BPA.SAAS.Manage.Comm.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.DiningPlate.Services
{
    public class DiningPlateService: IDiningPlateService, ITransient
    {
        /// <summary>
        /// 根据二维码修改餐盘信息（有就修改没有就新增）
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        public async Task<bool> EditDiningPlateByQRCode(DiningPlateCreateOrUpdataDto inputDto)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("GroupId", CurrentUser.GroupId);
            var url = App.Configuration["baseurl"] + "api/DiningPlate/EditDiningPlateByQRCode";
            var inputData = JsonConvert.SerializeObject(inputDto);
            var jsonData = HttpHelper.PostData(url, inputData, Encoding.UTF8, "application/json", dic);
            var data = JsonConvert.DeserializeObject<ResultSAASManageDto>(jsonData);
            if (data.statusCode != 200)
            {
                throw Oops.Oh(data.errors);
            }
            if (!Convert.ToBoolean(data.data))
            {throw Oops.Oh(ErrorCodeEnum.Code1001);}
            return true;
        }
    }
}
