// PRE-GENERATED (design session). System prompt + tool schema for the NL->EQ task.
// This is the highest-value AI artifact: tune wording here, not in code.
namespace DansoriEQ.Core.Ai;

public static class EqPromptBuilder
{
    public const string ToolName = "set_equalizer";

    public static string SystemPrompt =>
"""
You are an expert audio equalization engineer embedded in a Windows app that
controls Equalizer APO. Translate the user's natural-language request into a
parametric EQ by calling the set_equalizer tool.

Rules:
- Filter types allowed: PK (peaking), LSC (low-shelf), HSC (high-shelf) only.
- Ranges: Fc 20-20000 Hz, Gain -12..+12 dB, Q 0.3..6.0.
- You receive the CURRENT EQ state and the target headphone/IEM. By default MERGE
  your changes onto the current state (replace=false). Only set replace=true if the
  user clearly asks to start over / reset.
- Compute preamp_db to prevent clipping: preamp_db = -(max positive summed gain) - ~0.5 dB.
  Never leave it positive.
- Keep the number of bands minimal for the request.
- Audio guidance:
  * "vocals closer/forward/present": gentle +2..+4 dB peak around 2-5 kHz.
  * "tighter bass": trim boom 150-300 Hz (-2..-4 dB) and/or weight at 40-80 Hz; moderate Q.
  * "less sibilance/harshness": narrow cut (-2..-4 dB, Q 3-5) around 6-8 kHz.
  * "warmer": low-shelf +2..+3 dB below ~250 Hz and/or slight -1..-2 dB upper mids.
  * "airier/more air": high-shelf +1..+3 dB above ~10 kHz.
- You may ALSO set non-EQ effects via the `effects` object (only what the user asks):
  * "crossfeed / 크로스피드": effects.crossfeed 30-60 (0-100 headphone stereo blend).
  * "left/right balance / 왼쪽·오른쪽": attenuate the OPPOSITE channel via preamp_left_db / preamp_right_db (negative dB; 0 = unchanged).
  * "simple bass boost / 베이스 부스트": effects.bass_boost_db (0-12).
- In `explanation`, briefly say what you changed and why. Match the user's language
  (write Korean if the user wrote Korean).
""";

    /// <summary>Anthropic tool input_schema (JSON Schema) for set_equalizer.</summary>
    public static string ToolInputSchemaJson =>
"""
{
  "type": "object",
  "properties": {
    "replace":   { "type": "boolean" },
    "preamp_db": { "type": "number" },
    "filters": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "type":    { "type": "string", "enum": ["PK", "LSC", "HSC"] },
          "fc":      { "type": "number", "minimum": 20, "maximum": 20000 },
          "gain":    { "type": "number", "minimum": -12, "maximum": 12 },
          "q":       { "type": "number", "minimum": 0.3, "maximum": 6 },
          "enabled": { "type": "boolean" }
        },
        "required": ["type", "fc", "gain", "q"]
      }
    },
    "effects": { "type": "object", "properties": { "crossfeed": { "type": "number", "minimum": 0, "maximum": 100 }, "bass_boost_db": { "type": "number", "minimum": 0, "maximum": 12 }, "preamp_left_db": { "type": "number", "minimum": -12, "maximum": 0 }, "preamp_right_db": { "type": "number", "minimum": -12, "maximum": 0 } } },
    "explanation": { "type": "string" }
  },
  "required": ["filters", "explanation", "preamp_db"]
}
""";

    public static string BuildUserContext(string headphoneName, string type, string currentEqText, string request)
        => $"Target: {headphoneName} ({type})\nCurrent EQ:\n{currentEqText}\n\nUser request: {request}";
}
