// 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.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.HourlySchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicy;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class SimpleSchedulePolicyTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SimpleSchedulePolicy model =
            BinaryData
                .fromString(
                    "{\"schedulePolicyType\":\"SimpleSchedulePolicy\",\"scheduleRunFrequency\":\"Daily\",\"scheduleRunDays\":[\"Wednesday\",\"Tuesday\",\"Saturday\",\"Friday\"],\"scheduleRunTimes\":[\"2021-02-11T03:38:06Z\",\"2021-08-31T10:46:48Z\"],\"hourlySchedule\":{\"interval\":233622712,\"scheduleWindowStartTime\":\"2021-11-26T20:33:27Z\",\"scheduleWindowDuration\":1155433105},\"scheduleWeeklyFrequency\":1320154107}")
                .toObject(SimpleSchedulePolicy.class);
        Assertions.assertEquals(ScheduleRunType.DAILY, model.scheduleRunFrequency());
        Assertions.assertEquals(DayOfWeek.WEDNESDAY, model.scheduleRunDays().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-11T03:38:06Z"), model.scheduleRunTimes().get(0));
        Assertions.assertEquals(233622712, model.hourlySchedule().interval());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-11-26T20:33:27Z"), model.hourlySchedule().scheduleWindowStartTime());
        Assertions.assertEquals(1155433105, model.hourlySchedule().scheduleWindowDuration());
        Assertions.assertEquals(1320154107, model.scheduleWeeklyFrequency());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SimpleSchedulePolicy model =
            new SimpleSchedulePolicy()
                .withScheduleRunFrequency(ScheduleRunType.DAILY)
                .withScheduleRunDays(
                    Arrays.asList(DayOfWeek.WEDNESDAY, DayOfWeek.TUESDAY, DayOfWeek.SATURDAY, DayOfWeek.FRIDAY))
                .withScheduleRunTimes(
                    Arrays
                        .asList(
                            OffsetDateTime.parse("2021-02-11T03:38:06Z"), OffsetDateTime.parse("2021-08-31T10:46:48Z")))
                .withHourlySchedule(
                    new HourlySchedule()
                        .withInterval(233622712)
                        .withScheduleWindowStartTime(OffsetDateTime.parse("2021-11-26T20:33:27Z"))
                        .withScheduleWindowDuration(1155433105))
                .withScheduleWeeklyFrequency(1320154107);
        model = BinaryData.fromObject(model).toObject(SimpleSchedulePolicy.class);
        Assertions.assertEquals(ScheduleRunType.DAILY, model.scheduleRunFrequency());
        Assertions.assertEquals(DayOfWeek.WEDNESDAY, model.scheduleRunDays().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-11T03:38:06Z"), model.scheduleRunTimes().get(0));
        Assertions.assertEquals(233622712, model.hourlySchedule().interval());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-11-26T20:33:27Z"), model.hourlySchedule().scheduleWindowStartTime());
        Assertions.assertEquals(1155433105, model.hourlySchedule().scheduleWindowDuration());
        Assertions.assertEquals(1320154107, model.scheduleWeeklyFrequency());
    }
}
