#!perl
use Cassandane::Tiny;

sub test_card_set_create_basic
    :min_version_3_9
    ($self)
{
    xlog $self, "create addressbook";
    my $abook = $self->default_user->addressbooks->create({ name => 'Foo' });

    my $now = DateTime->now();
    my $created = $now->strftime('%Y-%m-%dT%H:%M:%SZ');
    my $prodid = '-//Example Corp.//CardDAV Client//EN';
    my $name = 'Mr. John Q. Public, Esq.';
    my $uid = 'ae2640cc-234a-4dd9-95cc-3106258445b9';

    my $card = $abook->create_card({
        '@type' => 'Card',
        version => '1.0',
        uid     => $uid,
        prodId  => $prodid,
        kind    => 'individual',
        created => $created,
        name    => { full => $name }
    });

    $self->assert_not_null($card->id);

    my $vcard = $card->as_vcard4_struct;

    $created = $now->strftime('%Y%m%dT%H%M%SZ'); # vCard doesn't use separators

    my sub prop {
        my ($v, $p) = @_;
        return [
            superhashof({
                value => $v,
                ($p ? (params => superhashof($p)) : ())
            }),
        ];
    }

    $self->assert_cmp_deeply(
        superhashof({
            properties => superhashof({
                created => prop($created),
                fn      => prop($name),
                kind    => prop('INDIVIDUAL'),
                prodid  => prop($prodid),
                uid     => prop($uid, { value => [ 'TEXT' ] }),
                version => prop('4.0'),
            })
        }),
        $vcard,
    );
}
