### ----------------------------------------------------
### -- WWW::GCloud
### -- Licenses: Artistic-2.0
### -- Authors: Vadim Belman
### -- File: t/030-rec-attr-aliasing.rakutest
### ----------------------------------------------------
use v6.e.PREVIEW;
use Test::Async;

use WWW::GCloud::Record;
use AttrX::Mooish;
use JSON::Class:auth<zef:vrurg>;

plan 8;

class SubRec {
    has $.x;
}

class TestRec is json(:implicit, :sorted-keys) is gc-record {
    has Str $.myFieldOfSomeKind;
    has Str $.kebabifyThisONEToo;
    has SubRec $.notForUse;
    has Int $.FooBar is json(:skip, :alias<fubar>);
}

cmp-deeply TestRec.new(:my-field-of-some-kind("is set"), :kebabify-this-onetoo("set too")),
           TestRec.new(:myFieldOfSomeKind("is set"), :kebabifyThisONEToo("set too")),
           "attribute names of a 'is gc-record' class are kebabified";

is TestRec.new(fubar => 31415926).FooBar, 31415926, ":alias attribute of `is json` trait";

class TestRecs is gc-record(:paginating(TestRec, "testRecords")) {}
class TestRecs2 is gc-record(:paginating(TestRec)) {}

ok ?TestRecs.^can('testRecords'), "paginating record has the specified camel case attribute accessor";
ok ?TestRecs.^can('test-records'), "paginating record has kebabified attribute accessor";

my $test-rec = TestRec.new(:my-field-of-some-kind("in folio"));
my $folio = TestRecs.new: page-token => "abd", test-records => ($test-rec,);

is $folio.items.elems, 1, "items attribute length";
is $folio.test-records.elems, 1, "kebabified items attribute length";
is $folio.testRecords.elems, 1, "camelized items attribute length";

cmp-ok $folio.items.head, &[===], $test-rec, "\$.items is  initialized with the original record";

done-testing;


