use v6.d;
use Test;

# use lib <. lib>;
use LLM::Tooling;

plan *;

## 1
subtest {
    # See https://docs.raku.org/language/pod#Declarator_blocks

    #| Base class for magicians
    class Magician {
        has Int $.level;
        has Str @.spells;
    }

    #| Fight mechanics.
    sub duel(
            Magician $a, #= First magician
            Magician $b, #= Second magician
            --> Int
             ) {
        return (rand > 0.5) + 1;
    }
    #= Magicians only, no mortals.

    #say sub-info(&duel);

    isa-ok sub-info(&duel), Map:D, 'expected type';

    is sub-info(&duel).keys.sort, <arity count description name parameters required returns> , 'expected keys';

    is sub-info(&duel)<description>, 'Fight mechanics. Magicians only, no mortals.', 'exepcted description';

    is sub-info(&duel)<parameters> ~~ Array:D | List:D, True, 'parameters are given in an array';

    is-deeply
            sub-info(&duel)<parameters>[0],
            ${:default(Any), :description("First magician"), :name("\$a"), :named(Bool::False), :optional(Bool::False), :position(0), :slurpy(Bool::False), :type((Magician))},
            'parameters are given in an array';

    is-deeply sub-info(&duel)<required>, ['$a', '$b'], 'expected value for the key "required"';

}, 'Magician duel sub';

## 2
subtest {

    #| Calculates the area of a rectangle given length and width.
    sub calculate-area(
            Numeric:D $length,       #= Length of the rectangle in units
            Numeric:D $width = 1,    #= Width of the rectangle in units
            Str:D :$unit = 'meters', #= Unit, one of meters or feet
            --> Numeric              #= Returns the area in square units
                       ) {
        return $length * $width;
    }

    #say llm-tool-definition(&calculate-area);
    isa-ok llm-tool-definition(&calculate-area, format => 'json'), Str:D;

}, 'LLM tool spec';

done-testing;
