using FI.FIC;
using FI.FIC.Contracts;
using FI.FIC.Contracts.DataObjects;
using FI.FIC.Contracts.DataObjects.Enumeration;
using FI.FIC.DataProviders.HelpClass;
using FI.FIC.Models;
using Foresight;
using IronIntel.Contractor.Users;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;

namespace IronIntel.Contractor
{
    public class HostRequesEntry
    {
        public static object ProcessNetRequest(FICNetRequestObject netQuery, HttpContext context)
        {
            switch (netQuery.MethodName)
            {
                case "ChangePassword":
                    var lc = FICHostEnvironment.GetCurrentLoginContext(context);
                    if (!UserManagement.ChangePassword(netQuery.LoginIID, netQuery.Parameters[0].ToString(), netQuery.Parameters[1].ToString(), lc.SessionID, context.Request.UserHostName))
                    {
                        throw new FIException(0X65026303, "", null);
                    }
                    break;
                case "LoginFIC"://跳转到G4，IronIntel没有G4版本
                    return "";
                case "GetVersion":
                    return SystemParams.GetFICVersion();
                default:
                    //rsp.Result = something
                    var service = new HostService();
                    service.Request = netQuery;
                    var method = typeof(HostService).GetMethod(netQuery.MethodName);
                    try
                    {
                        return method.Invoke(service, netQuery.Parameters);
                    }
                    catch (TargetInvocationException ex)
                    {
                        if (ex.InnerException != null)
                        {
                            throw ex.InnerException;
                        }
                        throw;
                    }
            }
            return null;
        }
    }



    public class LoginModel
    {
        public int ErrorCode { get; set; }
        public string Message { get; set; }
        public string Cookie { get; set; }
    }
}
