#!perl
use Cassandane::Tiny;

sub test_calendarevent_set_participants
    :min_version_3_4
    ($self)
{
    my $jmap = $self->default_user->jmap;

    my $calid = $self->default_user->calendars->default->id;

    my $event =  {
        "version" => "2.0",
        calendarIds => {
            $calid => JSON::true,
        },
        "title"=> "title",
        "description"=> "description",
        "start"=> "2015-11-07T09:00:00",
        "duration"=> "PT1H",
        "timeZone" => "Europe/London",
        "showWithoutTime"=> JSON::false,
        "freeBusyStatus"=> "busy",
        "status" => "confirmed",
        "organizerCalendarAddress" => "mailto:foo\@local",
        "participants" => {
            'foo' => {
                name => 'Foo',
                kind => 'individual',
                roles => {
                    'owner' => JSON::true,
                    'chair' => JSON::true,
                },
                participationStatus => 'accepted',
                expectReply => JSON::false,
                links => {
                    link1 => {
                        href => 'https://somelink.local',
                        rel => "enclosure",
                    },
                },
                calendarAddress => 'mailto:foo@local',
            },
            'bar' => {
                name => 'Bar',
                kind => 'individual',
                participationStatus => 'needs-action',
                expectReply => JSON::true,
                delegatedTo => {
                    'mailto:bam@local' => JSON::true,
                },
                memberOf => {
                    'mailto:groupimip@local' => JSON::true,
                },
                links => {
                    link1 => {
                        href => 'https://somelink.local',
                        rel => "enclosure",
                    },
                },
                email => 'bar2@local', # different email than calendarAddress
                calendarAddress => 'mailto:bar@local',
            },
            'bam' => {
                name => 'Bam',
                delegatedFrom => {
                    'mailto:bar@local' => JSON::true,
                },
                scheduleSequence => 7,
                scheduleUpdated => '2018-07-06T05:03:02Z',
                email => 'bam@local', # same email as calendarAddress
                calendarAddress => 'mailto:bam@local',
            },
            'group' => {
                name => 'Group',
                kind => 'group',
                email => 'group@local',
                calendarAddress => 'mailto:groupimip@local',
            },
            'resource' => {
                name => 'Some resource',
                kind => 'resource',
                calendarAddress => 'mailto:resource@local',
            },
            'location' => {
                name => 'Some location',
                kind => 'location',
                calendarAddress => 'mailto:location@local',
            },
        },
    };

    my $ret = $self->createandget_event($event);
    delete $event->{method};
    $self->assert_normalized_event_equals($event, $ret);
}
