#!perl
use Cassandane::Tiny;

sub test_calendarevent_set_custom_timezones
    :min_version_3_4 :needs_component_jmap
{
    my ($self) = @_;
    my $jmap = $self->{jmap};

    my $event1 = {
        calendarIds => {
            'Default' => JSON::true,
        },
        title => 'event1title',
        start => '2021-01-01T02:00:00',
        timeZone => '/customtzid',
        duration => 'PT1H',
        timeZones => {
            '/customtzid' => {
                '@type' => 'TimeZone',
                tzId => 'MyCustomTzId', # differs from "/customtzid"
                updated => '2021-01-01T01:00:00Z',
                url => 'https://local/customtzid',
                validUntil => '2022-01-01T01:00:00Z',
                aliases => {
                    MyCustomTzIdAlias => JSON::true,
                },
                standard => [{
                    '@type' => 'TimeZoneRule',
                    start => '2007-11-04T02:00:00',
                    offsetFrom => '-0400',
                    offsetTo => '-0500',
                    recurrenceRules => [{
                        '@type' => 'RecurrenceRule',
                        frequency => 'yearly',
                        byMonth => ['11'],
                        byDay => [{
                            '@type' => 'NDay',
                            day => 'su',
                            nthOfPeriod => 1,
                        }],
                        interval => 1,
                        rscale => 'gregorian',
                        firstDayOfWeek => 'mo',
                        skip => 'omit',
                    }],
                    names => {
                        'CUSTOMST' => JSON::true,
                    },
                    comments => ['customcomment'],
                }],
                daylight => [{
                    '@type' => 'TimeZoneRule',
                    start => '2007-03-11T02:00:00',
                    offsetFrom => '-0500',
                    offsetTo => '-0400',
                    recurrenceRules => [{
                        '@type' => 'RecurrenceRule',
                        frequency => 'yearly',
                        byMonth => ['3'],
                        byDay => [{
                            '@type' => 'NDay',
                            day => 'su',
                            nthOfPeriod => 2,
                        }],
                        interval => 1,
                        rscale => 'gregorian',
                        firstDayOfWeek => 'mo',
                        skip => 'omit',
                    }],
                    names => {
                        'CUSTOMDT' => JSON::true,
                    },
                    comments => ['customcomment'],
                }],
            },
        },
    };

    my $res = $jmap->CallMethods([
        ['CalendarEvent/set', {
            create => {
                event1 => $event1,
            },
        }, 'R1'],
        ['CalendarEvent/get', {
            ids => ['#event1'],
        }, 'R2'],
    ]);
    $self->assert_normalized_event_equals($event1, $res->[1][1]{list}[0]);
}
