using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using iHuman.UnitySz.Editor;
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
public enum SectionType
{
    Book,
    Practice,
    Say,
    Expand,
    GushiTravel,
    GushiThrough,
    GushiSay,
    GushiExercise,
    GushiSing,
    Weekly,
    Monthly
}

public static class SectionTypeExtensions
{
    private static readonly Dictionary<SectionType, string> _sectionTypeStrings = new Dictionary<SectionType, string>
    {
        { SectionType.Book, "book" },
        { SectionType.Practice, "practice" },
        { SectionType.Say, "say" },
        { SectionType.Expand, "expand" },
        { SectionType.GushiTravel, "gushi_travel_" },
        { SectionType.GushiThrough, "gushi_through_" },
        { SectionType.GushiSay, "gushi_say_" },
        { SectionType.GushiExercise, "gushi_exercise_exercise" },
        { SectionType.GushiSing, "gushi_sing_" },
        { SectionType.Weekly, "weekly" },
        { SectionType.Monthly, "monthly" }
    };

    public static string ToStringValue(this SectionType sectionType)
    {
        return _sectionTypeStrings[sectionType];
    }
    public static SectionType FromStringValue(string stringValue)
    {
        foreach (var kvp in _sectionTypeStrings)
        {
            if (stringValue.StartsWith(kvp.Value))
            {
                return kvp.Key;
            }
        }

        throw new ArgumentException($"Invalid section type string: {stringValue}");
    }
}


public class AppGameMake
{

    public static string moduleId = "";     //-moduleId

    public static void BuildBatch()
    {

        moduleId = BuildContext.GetArg("-moduleId", "");
        if (string.IsNullOrEmpty(moduleId))
        {
            throw new Exception("moduleId is null");
        }
        Build();
    }

    [MenuItem("Builder/module make", false, 9001)]
    public static void BuildEditor()
    {
        moduleId = ModuleResInputWindow.ShowWindow(true);
        if (string.IsNullOrEmpty(moduleId))
        {
            throw new Exception("moduleId is null");
        }
        Build();
    }

    public static void Build()
    {
        string resId = moduleId[^4..];
        SectionType sectionType = SectionTypeExtensions.FromStringValue(moduleId);
        switch (sectionType)
        {
            case SectionType.Book:
                BookTool.GenBook(resId);
                break;

            case SectionType.Practice:
                // todo
                break;

            case SectionType.Say:
                SayCreator.createSayResLink(resId);
                break;

            case SectionType.Expand:
                CopyVideoToFolder.GenExpandVideoReslink(resId);
                break;

            case SectionType.GushiTravel:
                // 无
                break;

            case SectionType.GushiThrough:
                ThroughGen.genOneThroughReslink(resId);
                break;

            case SectionType.GushiSay:
                // todo
                break;

            case SectionType.GushiExercise:
                // todo
                break;

            case SectionType.GushiSing:
                // 无
                break;

            case SectionType.Weekly:
                // todo
                break;

            case SectionType.Monthly:
                // 无
                break;
        }
    }


}