#!perl
use Cassandane::Tiny;

sub test_mailbox_get_inboxsub
    :min_version_3_1 :JMAPExtensions :NoAltNameSpace
{
    my ($self) = @_;

    my $jmap = $self->{jmap};
    my $imap = $self->{store}->get_client();

    # we need 'https://cyrusimap.org/ns/jmap/mail' capability for
    # isSeenShared property
    my @using = @{ $jmap->DefaultUsing() };
    push @using, 'https://cyrusimap.org/ns/jmap/mail';
    $jmap->DefaultUsing(\@using);

    xlog $self, "Create INBOX subfolder via IMAP";
    $imap->create("INBOX.INBOX.foo") or die;

    xlog $self, "Get mailboxes";
    my $res = $jmap->CallMethods([['Mailbox/get', {}, "R1"]]);
    $self->assert_num_equals(2, scalar @{$res->[0][1]{list}});

    my %mboxByName = map { $_->{name} => $_ } @{$res->[0][1]{list}};
    my $mboxfoo = $mboxByName{"foo"};
    my $inbox = $mboxByName{"Inbox"};

    $self->assert_str_equals('foo', $mboxfoo->{name});
    $self->assert_str_equals($inbox->{id}, $mboxfoo->{parentId});
    $self->assert_null($mboxfoo->{role});
    $self->assert_num_equals(10, $mboxfoo->{sortOrder});
    $self->assert_equals(JSON::true, $mboxfoo->{myRights}->{mayReadItems});
    $self->assert_equals(JSON::true, $mboxfoo->{myRights}->{mayAddItems});
    $self->assert_equals(JSON::true, $mboxfoo->{myRights}->{mayRemoveItems});
    $self->assert_equals(JSON::true, $mboxfoo->{myRights}->{mayCreateChild});
    $self->assert_equals(JSON::true, $mboxfoo->{myRights}->{mayRename});
    $self->assert_equals(JSON::true, $mboxfoo->{myRights}->{mayDelete});
    $self->assert_num_equals(0, $mboxfoo->{totalEmails});
    $self->assert_num_equals(0, $mboxfoo->{unreadEmails});
    $self->assert_num_equals(0, $mboxfoo->{totalThreads});
    $self->assert_num_equals(0, $mboxfoo->{unreadThreads});
    $self->assert_num_equals(JSON::false, $mboxfoo->{isSeenShared});
}
