namespace RealCV.Infrastructure.Helpers;

/// <summary>
/// Helper methods for processing AI/LLM JSON responses.
/// </summary>
public static class JsonResponseHelper
{
    /// <summary>
    /// Cleans a JSON response by removing markdown code block formatting.
    /// </summary>
    public static string CleanJsonResponse(string response)
    {
        var trimmed = response.Trim();

        // Remove markdown code blocks
        if (trimmed.StartsWith("```json", StringComparison.OrdinalIgnoreCase))
        {
            trimmed = trimmed[7..];
        }
        else if (trimmed.StartsWith("```"))
        {
            trimmed = trimmed[3..];
        }

        if (trimmed.EndsWith("```"))
        {
            trimmed = trimmed[..^3];
        }

        return trimmed.Trim();
    }
}
