using System;
using System.Collections.Generic;
using System.Text;
using ChuPiao.Common.Enums;

namespace ChuPiao.Common.Communication.CpdJson.Packs
{
    /// <summary>
    /// 投注号码工具类
    /// </summary>
    public class CodeUtil
    {
        /// <summary>
        /// 竟彩投注号码拆分
        /// </summary>
        /// <param name="playId"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static List<JcOneMatchCodeEntity> JcCodeSplit(int playId,string code)
        {
            //比分及混串中的比分号码格式转换
            if(playId==91102 || playId==91199)
            {
                code=code.Replace("胜其它", "9:0").Replace("平其它", "9:9").Replace("负其它", "0:9");
            }
            List<JcOneMatchCodeEntity> result=new List<JcOneMatchCodeEntity>();
            string[] arr = code.Split('/');
            foreach (string s in arr)
            {
                result.Add(new JcOneMatchCodeEntity(s));
            }
            return result;
        }

        /// <summary>
        /// 常规彩号码转换
        /// </summary>
        /// <param name="lotId"></param>
        /// <param name="playId"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string CgCodeConvert(int lotId,int playId,string code)
        {
            string result = code;
            Lottype lottype = (Lottype) lotId;
            switch (lottype)
            {
                case Lottype.Sf:
                    result = code.Replace("|", ",");
                    break;
                case Lottype.Xs:
                    result = code.Replace("$", ",");
                    break;
            }
            return result;
        }
    }
    /// <summary>
    /// 竟彩某场次的投注号码
    /// </summary>
    public class JcOneMatchCodeEntity
    {
        public JcOneMatchCodeEntity(string oneMatchCode)
        {
            //4001→[0]/4002→[1,0]/4003→[0]/4004→[3]
            //7004→91103[1,2,3]/7006→91101[3]/7021→91101[0]/7030→91101[3]
            int index1 = oneMatchCode.IndexOf('→');
            int index2 = oneMatchCode.IndexOf('[');
            int index3 = oneMatchCode.IndexOf(']');
            _match = oneMatchCode.Substring(0, index1);
            if(index2-index1>1)
            {
                //混串玩法
                _playId = int.Parse(oneMatchCode.Substring(index1 + 1, index2 - index1 - 1));
            }
            _code = oneMatchCode.Substring(index2 + 1, index3 - index2 - 1);
        }
        public JcOneMatchCodeEntity(string match,string code,int? playId)
        {
            _match = match;
            _code = code;
            _playId = playId;
        }
        public JcOneMatchCodeEntity()
        {
            
        }
        private string _match="";
        private string _code="";
        private int ? _playId;

        public string Match
        {
            get { return _match; }
            set { _match = value; }
        }

        public string Code
        {
            get { return _code; }
            set { _code = value; }
        }

        public int? PlayId
        {
            get { return _playId; }
            set { _playId = value; }
        }
        public override string ToString()
        {
            return string.Format("{0}→{1}[{2}]",_match,_playId.HasValue?_playId.ToString():"",_code);
        }
    }
}
