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 ScfCreateUrlRequestV1 : BocomEncryptRequest<ScfCreateUrlResponseV1>
        {
            private string encryptType = BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4;

            private string encryptKey = SM4KeyGen.GenSM4Key();


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


            public override bool IsNeedEncrypt()
            {
                return true;
            }

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

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

            [DataContract]
            public class ScfCreateUrlRequestV1Biz : BizContent
            {
                [DataMember]
                public string com_no { get; set; }
            }

            public override string GetEncryptPolicy()
            {
                // TODO Auto-generated method stub
                return "FIELD";
            }

            public override string GetEncryptType()
            {
                // TODO Auto-generated method stub
                return encryptType;
            }


            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;
            }
        }
    }
}