//! Word metadata for sequencing: probability, timing, context queries, generators.

use super::{Word, WordCompile::*};

pub(super) const WORDS: &[Word] = &[
    // Probability
    Word {
        name: "rand",
        aliases: &[],
        category: "Probability",
        stack: "(min max -- n|f)",
        desc: "Random in range. Int if both args are int, float otherwise",
        example: "1 6 rand => 4 | 0.0 1.0 rand => 0.42",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "exprand",
        aliases: &[],
        category: "Probability",
        stack: "(lo hi -- f)",
        desc: "Exponential random biased toward lo. Both args must be positive",
        example: "1.0 100.0 exprand => 3.7",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "logrand",
        aliases: &[],
        category: "Probability",
        stack: "(lo hi -- f)",
        desc: "Exponential random biased toward hi. Both args must be positive",
        example: "1.0 100.0 logrand => 87.2",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "seed",
        aliases: &[],
        category: "Probability",
        stack: "(n --)",
        desc: "Set random seed",
        example: "12345 seed",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "coin",
        aliases: &[],
        category: "Probability",
        stack: "(-- bool)",
        desc: "50/50 random boolean",
        example: "coin => 0 or 1",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "chance",
        aliases: &[],
        category: "Probability",
        stack: "(quot prob --)",
        desc: "Execute quotation with probability (0.0-1.0)",
        example: "( 2 distort ) 0.75 chance",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "prob",
        aliases: &[],
        category: "Probability",
        stack: "(quot pct --)",
        desc: "Execute quotation with probability (0-100)",
        example: "( 2 distort ) 75 prob",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "choose",
        aliases: &[],
        category: "Probability",
        stack: "(..n n -- val)",
        desc: "Random pick from n items",
        example: "1 2 3 3 choose",
        compile: Simple,
        varargs: true,
    },
    Word {
        name: "cycle",
        aliases: &[],
        category: "Probability",
        stack: "(v1..vn n -- selected)",
        desc: "Cycle through n items by step runs",
        example: "60 64 67 3 cycle",
        compile: Simple,
        varargs: true,
    },
    Word {
        name: "pcycle",
        aliases: &[],
        category: "Probability",
        stack: "(v1..vn n -- selected)",
        desc: "Cycle through n items by pattern iteration",
        example: "60 64 67 3 pcycle",
        compile: Simple,
        varargs: true,
    },
    Word {
        name: "bounce",
        aliases: &[],
        category: "Probability",
        stack: "(v1..vn n -- selected)",
        desc: "Ping-pong cycle through n items by step runs",
        example: "60 64 67 72 4 bounce",
        compile: Simple,
        varargs: true,
    },
    Word {
        name: "pbounce",
        aliases: &[],
        category: "Probability",
        stack: "(v1..vn n -- selected)",
        desc: "Ping-pong cycle through n items by pattern iteration",
        example: "60 64 67 72 4 pbounce",
        compile: Simple,
        varargs: true,
    },
    Word {
        name: "index",
        aliases: &[],
        category: "Probability",
        stack: "(v1..vn n idx -- selected)",
        desc: "Select item at explicit index",
        example: "[ c4 e4 g4 ] step index",
        compile: Simple,
        varargs: true,
    },
    Word {
        name: "wchoose",
        aliases: &[],
        category: "Probability",
        stack: "(v1 w1 v2 w2 ... n -- selected)",
        desc: "Weighted random pick from n value/weight pairs",
        example: "60 0.6  64 0.3  67 0.1  3 wchoose",
        compile: Simple,
        varargs: true,
    },
    Word {
        name: "always",
        aliases: &[],
        category: "Probability",
        stack: "(quot --)",
        desc: "Always execute quotation",
        example: "( 2 distort ) always",
        compile: Probability(1.0),
        varargs: false,
    },
    Word {
        name: "never",
        aliases: &[],
        category: "Probability",
        stack: "(quot --)",
        desc: "Never execute quotation",
        example: "( 2 distort ) never",
        compile: Probability(0.0),
        varargs: false,
    },
    Word {
        name: "often",
        aliases: &[],
        category: "Probability",
        stack: "(quot --)",
        desc: "Execute quotation 75% of the time",
        example: "( 2 distort ) often",
        compile: Probability(0.75),
        varargs: false,
    },
    Word {
        name: "sometimes",
        aliases: &[],
        category: "Probability",
        stack: "(quot --)",
        desc: "Execute quotation 50% of the time",
        example: "( 2 distort ) sometimes",
        compile: Probability(0.5),
        varargs: false,
    },
    Word {
        name: "rarely",
        aliases: &[],
        category: "Probability",
        stack: "(quot --)",
        desc: "Execute quotation 25% of the time",
        example: "( 2 distort ) rarely",
        compile: Probability(0.25),
        varargs: false,
    },
    Word {
        name: "almostNever",
        aliases: &[],
        category: "Probability",
        stack: "(quot --)",
        desc: "Execute quotation 10% of the time",
        example: "( 2 distort ) almostNever",
        compile: Probability(0.1),
        varargs: false,
    },
    Word {
        name: "almostAlways",
        aliases: &[],
        category: "Probability",
        stack: "(quot --)",
        desc: "Execute quotation 90% of the time",
        example: "( 2 distort ) almostAlways",
        compile: Probability(0.9),
        varargs: false,
    },
    // Time
    Word {
        name: "every",
        aliases: &[],
        category: "Time",
        stack: "(quot n --)",
        desc: "Execute quotation every nth iteration",
        example: "( 2 distort ) 4 every",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "except",
        aliases: &[],
        category: "Time",
        stack: "(quot n --)",
        desc: "Execute quotation on all iterations except every nth",
        example: "( 2 distort ) 4 except",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "every+",
        aliases: &[],
        category: "Time",
        stack: "(quot n offset --)",
        desc: "Execute quotation every nth iteration with phase offset",
        example: "( snare ) 4 2 every+ => fires at iter 2, 6, 10...",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "except+",
        aliases: &[],
        category: "Time",
        stack: "(quot n offset --)",
        desc: "Skip quotation every nth iteration with phase offset",
        example: "( snare ) 4 2 except+ => skips at iter 2, 6, 10...",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "bjork",
        aliases: &[],
        category: "Time",
        stack: "(quot k n --)",
        desc: "Execute quotation using Euclidean distribution over step runs",
        example: "( 2 distort ) 3 8 bjork",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "pbjork",
        aliases: &[],
        category: "Time",
        stack: "(quot k n --)",
        desc: "Execute quotation using Euclidean distribution over pattern iterations",
        example: "( 2 distort ) 3 8 pbjork",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "loop",
        aliases: &[],
        category: "Time",
        stack: "(n --)",
        desc: "Fit sample to n beats",
        example: "\"break\" s 4 loop @",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "tempo!",
        aliases: &[],
        category: "Time",
        stack: "(bpm --)",
        desc: "Set global tempo",
        example: "140 tempo!",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "speed!",
        aliases: &[],
        category: "Time",
        stack: "(multiplier --)",
        desc: "Set pattern speed multiplier",
        example: "2.0 speed!",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "at",
        aliases: &[],
        category: "Time",
        stack: "(v1..vn --)",
        desc: "Set delta context for emit timing",
        example: "0 0.5 at kick s . => emits at 0 and 0.5 of step",
        compile: Simple,
        varargs: true,
    },
    // Context
    Word {
        name: "step",
        aliases: &[],
        category: "Context",
        stack: "(-- n)",
        desc: "Current step index",
        example: "step => 0",
        compile: Context("step"),
        varargs: false,
    },
    Word {
        name: "beat",
        aliases: &[],
        category: "Context",
        stack: "(-- f)",
        desc: "Current beat position",
        example: "beat => 4.5",
        compile: Context("beat"),
        varargs: false,
    },
    Word {
        name: "pattern",
        aliases: &[],
        category: "Context",
        stack: "(-- n)",
        desc: "Current pattern index",
        example: "pattern => 0",
        compile: Context("pattern"),
        varargs: false,
    },
    Word {
        name: "pbank",
        aliases: &[],
        category: "Context",
        stack: "(-- n)",
        desc: "Current pattern's bank index",
        example: "pbank => 0",
        compile: Context("bank"),
        varargs: false,
    },
    Word {
        name: "tempo",
        aliases: &[],
        category: "Context",
        stack: "(-- f)",
        desc: "Current BPM",
        example: "tempo => 120.0",
        compile: Context("tempo"),
        varargs: false,
    },
    Word {
        name: "phase",
        aliases: &[],
        category: "Context",
        stack: "(-- f)",
        desc: "Phase in bar (0-1)",
        example: "phase => 0.25",
        compile: Context("phase"),
        varargs: false,
    },
    Word {
        name: "slot",
        aliases: &[],
        category: "Context",
        stack: "(-- n)",
        desc: "Current slot number",
        example: "slot => 0",
        compile: Context("slot"),
        varargs: false,
    },
    Word {
        name: "runs",
        aliases: &[],
        category: "Context",
        stack: "(-- n)",
        desc: "Times this step ran",
        example: "runs => 3",
        compile: Context("runs"),
        varargs: false,
    },
    Word {
        name: "iter",
        aliases: &[],
        category: "Context",
        stack: "(-- n)",
        desc: "Pattern iteration count",
        example: "iter => 2",
        compile: Context("iter"),
        varargs: false,
    },
    Word {
        name: "stepdur",
        aliases: &[],
        category: "Context",
        stack: "(-- f)",
        desc: "Step duration in seconds",
        example: "stepdur => 0.125",
        compile: Context("stepdur"),
        varargs: false,
    },
    Word {
        name: "fill",
        aliases: &[],
        category: "Context",
        stack: "(-- bool)",
        desc: "True when fill is on (f key)",
        example: "\"snare\" s . fill ?",
        compile: Context("fill"),
        varargs: false,
    },
    // Desktop
    #[cfg(feature = "desktop")]
    Word {
        name: "mx",
        aliases: &[],
        category: "Desktop",
        stack: "(-- x)",
        desc: "Normalized mouse X position (0-1)",
        example: "mx 440 880 range freq",
        compile: Context("mx"),
        varargs: false,
    },
    #[cfg(feature = "desktop")]
    Word {
        name: "my",
        aliases: &[],
        category: "Desktop",
        stack: "(-- y)",
        desc: "Normalized mouse Y position (0-1)",
        example: "my 0.1 0.9 range gain",
        compile: Context("my"),
        varargs: false,
    },
    #[cfg(feature = "desktop")]
    Word {
        name: "mdown",
        aliases: &[],
        category: "Desktop",
        stack: "(-- bool)",
        desc: "1 when mouse button held, 0 otherwise",
        example: "mdown ( \"crash\" s . ) ?",
        compile: Context("mdown"),
        varargs: false,
    },
    // Generator
    Word {
        name: "..",
        aliases: &[],
        category: "Generator",
        stack: "(start end -- start start+1 ... end)",
        desc: "Push arithmetic sequence from start to end",
        example: "1 4 .. => 1 2 3 4",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: ".,",
        aliases: &[],
        category: "Generator",
        stack: "(start end step -- start start+step ...)",
        desc: "Push arithmetic sequence with custom step",
        example: "0 1 0.25 ., => 0 0.25 0.5 0.75 1",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "gen",
        aliases: &[],
        category: "Generator",
        stack: "(quot n -- results...)",
        desc: "Execute quotation n times, push all results",
        example: "( 1 6 rand ) 4 gen => 4 random values",
        compile: Simple,
        varargs: true,
    },
    Word {
        name: "geom..",
        aliases: &[],
        category: "Generator",
        stack: "(start ratio count -- start start*r start*r^2 ...)",
        desc: "Push geometric sequence",
        example: "1 2 4 geom.. => 1 2 4 8",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "euclid",
        aliases: &[],
        category: "Generator",
        stack: "(k n -- i1 i2 ... ik)",
        desc: "Push indices for k hits evenly distributed over n steps",
        example: "4 8 euclid => 0 2 4 6",
        compile: Simple,
        varargs: false,
    },
    Word {
        name: "euclidrot",
        aliases: &[],
        category: "Generator",
        stack: "(k n r -- i1 i2 ... ik)",
        desc: "Push Euclidean indices with rotation r",
        example: "3 8 2 euclidrot => 1 4 6",
        compile: Simple,
        varargs: false,
    },
];
