using Assets.Native.tools.excel.Atrtribute;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Assets.app.Editor.tools.PoetryConfig.common {
    public class BaseConfigModel {
        [ExcelColumnAttribute("周课ID")]
        public string WeeklyId;

        [ExcelColumnAttribute("题目")]
        public string Title;

        [ExcelColumnAttribute("朝代")]
        public string Dynasty;

        [ExcelColumnAttribute("诗人")]
        public string Author;

        [ExcelColumnAttribute("内容")]
        public string Content;

        [ExcelColumnAttribute("pinyin_timu")]
        public string PYTitile;

        [ExcelColumnAttribute("pinyin_chaodai")]
        public string PYDynasty;

        [ExcelColumnAttribute("pinyin_shiren")]
        public string PYAuthor;

        [ExcelColumnAttribute("pinyin_neirong")]
        public string PYContent;

        // 非表列 
        public string ReadId;
        public string Sentences;
        public string Separators;

        public void init() {
            SplitContetIntoList();
        }

        public void SplitContetIntoList() {
            // 正则表达式匹配常见的中文标点符号
            string splitPattern = @"(?<=[，。！？,])\s*";
            string punctuationPattern = @"[，。！？]$";
            List<string> ContentList = new List<string>();
            List<string> SeparatorList = new List<string>();

            // 使用正则表达式分割古诗，并保留标点符号
            List<string> separatedContent = new List<string>(Regex.Split(Content, splitPattern));
            separatedContent.Remove("");
            foreach(string onePoetry in separatedContent) {
                string punctuation = "";
                string poetry = onePoetry;
                if(Regex.IsMatch(onePoetry,punctuationPattern)) {
                    punctuation = onePoetry.Substring(onePoetry.Length - 1, 1);
                    poetry = onePoetry.Substring(0, onePoetry.Length - 1);
                }
                ContentList.Add(poetry);
                SeparatorList.Add(punctuation);
            }
            Sentences = string.Join(",",ContentList);
            Separators = string.Join(",",SeparatorList);
        }
    }
}