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

namespace Assets.Native.tools.excel.Model {


    [DataContract]
    class SayModel
    {
        [DataMember(Name = "PoetryTitle", EmitDefaultValue = false)]
        public string Title;

        [DataMember(Name = "PoetryDynasty", EmitDefaultValue = false)]
        public string Dynasty;

        [DataMember(Name = "PoetryAuthor", EmitDefaultValue = false)]
        public string Author;

        [DataMember(Name = "PoetryContent", EmitDefaultValue = false)]
        public string[] Content;

        [DataMember(Name = "PoetryPYTitle", EmitDefaultValue = false)]
        public string PYTitle;

        [DataMember(Name = "PoetryPYDynasty", EmitDefaultValue = false)]
        public string PYDynasty;

        [DataMember(Name = "PoetryPYAuthor", EmitDefaultValue = false)]
        public string PYAuthor;

        [DataMember(Name = "PoetryPYContent", EmitDefaultValue = false)]
        public string[] PYContent;
    }
    [DataContract]
    class WeelkyModel
    {

        [DataMember(Name = "Month", EmitDefaultValue = false)]
        public string Month;

        [DataMember(Name = "ID", EmitDefaultValue = false)]
        public string ID;

        [DataMember(Name = "Week", EmitDefaultValue = false)]
        public string Week;

        [DataMember(Name = "PracticeConfig", EmitDefaultValue = false)]
        public PracticeBaseConfigOutPutModel PracticeBaseConfigOutPutModel;

        [DataMember(Name = "SayConfig", EmitDefaultValue = false)]
        public SayModel SayModel = new SayModel();

        public WeelkyModel(List<WeeklyPracticeModel> weeklyPracticeModels, WeeklySayModel weeklySayModel)
        {

            Month = weeklySayModel.Month;
            ID = weeklySayModel.ID;
            Week = weeklySayModel.Week;
            SayModel.Title = weeklySayModel.Title;
            SayModel.Dynasty = weeklySayModel.Dynasty;
            SayModel.Author = weeklySayModel.Author;

            // 正则表达式匹配常见的中文标点符号
            string pattern = @"(?<=[，。！？,])\s*";

            // 使用正则表达式分割古诗，并保留标点符号
            string[] lines = Regex.Split(weeklySayModel.Content, pattern);
            if (lines.Length > 0 && string.IsNullOrWhiteSpace(lines[^1]))
            {
                Array.Resize(ref lines, lines.Length - 1);
            }
            SayModel.Content = lines;


            SayModel.PYTitle = weeklySayModel.PYTitle;
            SayModel.PYDynasty = weeklySayModel.PYDynasty;
            SayModel.PYAuthor = weeklySayModel.PYAuthor;
            // 使用正则表达式分割古诗，并保留标点符号
            if(!string.IsNullOrEmpty(weeklySayModel.PYContent))
            {
                string[] PYlines = Regex.Split(weeklySayModel.PYContent, pattern);
                if (PYlines.Length > 0 && string.IsNullOrWhiteSpace(PYlines[^1]))
                {
                    Array.Resize(ref PYlines, PYlines.Length - 1);
                }
                SayModel.PYContent = PYlines;
            }

            List<PracticeBaseConfigModel> PracticeBaseConfigModels = new List<PracticeBaseConfigModel>();
            weeklyPracticeModels.ForEach(practiceExcelContent => PracticeBaseConfigModels.Add(new PracticeBaseConfigModel(practiceExcelContent)));
            PracticeBaseConfigOutPutModel = new PracticeBaseConfigOutPutModel(PracticeBaseConfigModels, weeklyPracticeModels[0].Version);
        }
    }
}
