using CsharpHttpHelper;
using DeviceRepairAndOptimization.Data.FormManager;
using DeviceRepairAndOptimization.Models;
using DeviceRepairAndOptimization.Models.Drives;
using DeviceRepairAndOptimization.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace DeviceRepairAndOptimization.Business
{
    public class FormManager
    {
        private static FormManager manager;
        public static FormManager Instance
        {
            get
            {
                if (manager == null)
                    manager = new FormManager();
                return manager;
            }
        }

        /// <summary>
        /// 分配点检表到指定设备
        /// </summary>
        /// <param name="lst"></param>
        /// <returns></returns>
        public APIResponseData AssigningFormToDevices(List<SubmitAssignFormsToDevices> lst)
        {
            APIResponseData result = new APIResponseData { Code = -1, Message = "操作失败！" };
            try
            {
                switch (Models.Config.Configurations.Properties.ConnType?.ToLower())
                {
                    case "api":
                        result = ApiHelper.Instance.SendMessage(new HttpItem
                        {
                            URL = ServiceRoute.AssigningFormToDevices,
                            Method = "Post",
                            ContentType = "application/json;charset=utf-8",
                            Postdata = JsonConvert.SerializeObject(lst.ToArrayAndCompress())
                        });
                        break;

                    default:
                        result = FormAccess.Instance.AssigningFormToDevices(lst);
                        break;
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
            }
            return result;
        }
    }
}
