using System;
using System.Collections.Generic;
using System.Linq;

namespace AxCopilot.Services.Agent;

public class SkillDefinition
{
	public string Id { get; init; } = "";

	public string Name { get; init; } = "";

	public string Label { get; init; } = "";

	public string Description { get; init; } = "";

	public string Icon { get; init; } = "\ue768";

	public string SystemPrompt { get; init; } = "";

	public string FilePath { get; init; } = "";

	public string License { get; init; } = "";

	public string Compatibility { get; init; } = "";

	public string AllowedTools { get; init; } = "";

	public string Requires { get; init; } = "";

	public string Tabs { get; init; } = "all";

	public bool IsAvailable { get; set; } = true;

	public bool IsStandardFormat => FilePath.EndsWith("SKILL.md", StringComparison.OrdinalIgnoreCase);

	public string UnavailableHint
	{
		get
		{
			if (IsAvailable || string.IsNullOrEmpty(Requires))
			{
				return "";
			}
			IEnumerable<string> source = from r in Requires.Split(',')
				select r.Trim();
			string[] array = source.Where((string r) => !RuntimeDetector.IsAvailable(r)).ToArray();
			return (array.Length != 0) ? ("(" + string.Join(", ", array.Select((string r) => char.ToUpper(r[0]) + r.Substring(1, r.Length - 1))) + " 필요)") : "";
		}
	}

	public bool IsVisibleInTab(string activeTab)
	{
		if (string.IsNullOrEmpty(Tabs) || Tabs.Equals("all", StringComparison.OrdinalIgnoreCase))
		{
			return true;
		}
		IEnumerable<string> source = from t in Tabs.Split(',')
			select t.Trim().ToLowerInvariant();
		string tab = activeTab.ToLowerInvariant();
		return source.Any((string t) => t == "all" || t == tab);
	}
}
