using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Assets.Native.tools.excel.Util;
using CommonUtil;
using EditorUtils;
using Newtonsoft.Json;
using UnityEditor;
using UnityEditor.Timeline.Actions;
using iHuman.UnitySz.Framework;
using UnityEngine;
using System.Threading.Tasks;
using Assets.app.Editor.tools.PoetryConfig.common;

 
public class FetchSayAudio
{
    static String resultDirRoot = "Assets/art/game/gushi/say"; //Assets/art/game/gushi/say/0016/sound
    static String weeklySoundSvn = "https://10.3.254.33/repos/hongen_read/product/sound/周课/";  //https://10.3.254.33/repos/hongen_read/product/sound/周课/0197

    [MenuItem("Assets/自定义创建/古诗/say/拉取音频并生成img&sound的reslink")]
    public static void fetchSayAudio() {
        List<BaseConfigModel> modelList = BaseConfigGenNew.GenBaseConfigModelList();
        foreach (BaseConfigModel model in modelList) {
            string readId = model.ReadId;
            string weeklyId = model.WeeklyId;
            if(!String.IsNullOrWhiteSpace(readId) && !String.IsNullOrWhiteSpace(weeklyId)) {
                string soundSvnPath = weeklySoundSvn + weeklyId;
                string soundDir = SvnUtil.getDir(soundSvnPath,"files");
                string destFolder = $"Assets/art/game/gushi/say/{readId}/sound/poetries";
                if (!Directory.Exists(destFolder)) Directory.CreateDirectory(destFolder);
                string[] files = Directory.GetFiles(soundDir);
                foreach (string file in files)
                {
                    string fileName = Path.GetFileName(file);
                    if (fileName.StartsWith("poetry")) {

                        string destinationFilePath = Path.Combine(destFolder, fileName);
                        File.Copy(file, destinationFilePath, true);
                    }
                }
            }
        }
        ReslinkGen.genSayResLink();
    }
}