using System;
using System.Runtime.Serialization;
using Com.Bocom.OpenApi.Response;
using Com.Bocom.OpenApi.Security.KeyGen;
using Com.Bocom.OpenApi.Utils;

namespace Com.Bocom.OpenApi
{
    namespace Request
    {
        public class BJPTBlCustAccountQueryRequestV1 : BocomEncryptRequest<BJPTBlCustAccountQueryResponseV1>
        {
            private string encryptType = BocomConstants.ENCRYPT_TYPE_RSA_AND_AES;

            private string encryptKey = AESKeyGen.GenAES256Key();


            public override Type GetResponseClass()
            {
                return typeof(BJPTBlCustAccountQueryResponseV1);
            }

            public override bool IsNeedEncrypt()
            {
                return true;
            }

            public override string GetMethod()
            {
                return "POST";
            }

            public override Type GetBizContentClass()
            {
                return typeof(BlCustAccountQueryRequestV1Biz);
            }

            [DataContract]
            public class BlCustAccountQueryRequestV1Biz : BizContent
            {
                [DataMember]
                public string req_usercode { get; set; }

                [DataMember]
                public string field1 { get; set; }

                [DataMember]
                public string cust_idno { get; set; }

                [DataMember]
                public string balance_account { get; set; }

                [DataMember]
                public string cust_erpid { get; set; }

                [DataMember]
                public string field2 { get; set; }
            }

            public override string GetEncryptPolicy()
            {
                return BocomConstants.ENCRYPT_POLICY_TYPE_CONTENT;
            }

            public override string GetEncryptType()
            {
                return encryptType;
            }

            public void setEncryptType(string encryptType)
            {
                if (encryptType.Equals(BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4))
                {
                    this.encryptType = encryptType;
                    encryptKey = SM4KeyGen.GenSM4Key();
                }
            }

            public override string Encrypt(string data, string key, string encryptType)
            {
                string cipher;
                try
                {
                    cipher = BocomEncrypt.SymmetricalEncrypt(data, encryptType, key, BocomConstants.CHARSET_UTF8);
                }
                catch (Exception e)
                {
                    throw new Exception("加密字符串[" + data + "]时遇到异常", e);
                }

                return cipher;
            }

            public override string GetEncryptKey()
            {
                return encryptKey;
            }
        }
    }
}