// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.recoveryservicesbackup.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailySchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.HourlySchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicyV2;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklySchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class SimpleSchedulePolicyV2Tests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SimpleSchedulePolicyV2 model =
            BinaryData
                .fromString(
                    "{\"schedulePolicyType\":\"SimpleSchedulePolicyV2\",\"scheduleRunFrequency\":\"Invalid\",\"hourlySchedule\":{\"interval\":593707947,\"scheduleWindowStartTime\":\"2021-06-23T19:26:24Z\",\"scheduleWindowDuration\":1408451637},\"dailySchedule\":{\"scheduleRunTimes\":[\"2021-10-14T21:01:05Z\",\"2021-03-20T12:18Z\"]},\"weeklySchedule\":{\"scheduleRunDays\":[\"Monday\"],\"scheduleRunTimes\":[\"2021-05-21T16:02:15Z\",\"2021-02-15T03:37:38Z\",\"2021-01-09T17:48:34Z\",\"2021-05-14T12:19:22Z\"]}}")
                .toObject(SimpleSchedulePolicyV2.class);
        Assertions.assertEquals(ScheduleRunType.INVALID, model.scheduleRunFrequency());
        Assertions.assertEquals(593707947, model.hourlySchedule().interval());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-06-23T19:26:24Z"), model.hourlySchedule().scheduleWindowStartTime());
        Assertions.assertEquals(1408451637, model.hourlySchedule().scheduleWindowDuration());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-10-14T21:01:05Z"), model.dailySchedule().scheduleRunTimes().get(0));
        Assertions.assertEquals(DayOfWeek.MONDAY, model.weeklySchedule().scheduleRunDays().get(0));
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-05-21T16:02:15Z"), model.weeklySchedule().scheduleRunTimes().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SimpleSchedulePolicyV2 model =
            new SimpleSchedulePolicyV2()
                .withScheduleRunFrequency(ScheduleRunType.INVALID)
                .withHourlySchedule(
                    new HourlySchedule()
                        .withInterval(593707947)
                        .withScheduleWindowStartTime(OffsetDateTime.parse("2021-06-23T19:26:24Z"))
                        .withScheduleWindowDuration(1408451637))
                .withDailySchedule(
                    new DailySchedule()
                        .withScheduleRunTimes(
                            Arrays
                                .asList(
                                    OffsetDateTime.parse("2021-10-14T21:01:05Z"),
                                    OffsetDateTime.parse("2021-03-20T12:18Z"))))
                .withWeeklySchedule(
                    new WeeklySchedule()
                        .withScheduleRunDays(Arrays.asList(DayOfWeek.MONDAY))
                        .withScheduleRunTimes(
                            Arrays
                                .asList(
                                    OffsetDateTime.parse("2021-05-21T16:02:15Z"),
                                    OffsetDateTime.parse("2021-02-15T03:37:38Z"),
                                    OffsetDateTime.parse("2021-01-09T17:48:34Z"),
                                    OffsetDateTime.parse("2021-05-14T12:19:22Z"))));
        model = BinaryData.fromObject(model).toObject(SimpleSchedulePolicyV2.class);
        Assertions.assertEquals(ScheduleRunType.INVALID, model.scheduleRunFrequency());
        Assertions.assertEquals(593707947, model.hourlySchedule().interval());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-06-23T19:26:24Z"), model.hourlySchedule().scheduleWindowStartTime());
        Assertions.assertEquals(1408451637, model.hourlySchedule().scheduleWindowDuration());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-10-14T21:01:05Z"), model.dailySchedule().scheduleRunTimes().get(0));
        Assertions.assertEquals(DayOfWeek.MONDAY, model.weeklySchedule().scheduleRunDays().get(0));
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-05-21T16:02:15Z"), model.weeklySchedule().scheduleRunTimes().get(0));
    }
}
