// 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.DailyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.Day;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class YearlyRetentionScheduleTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        YearlyRetentionSchedule model =
            BinaryData
                .fromString(
                    "{\"retentionScheduleFormatType\":\"Weekly\",\"monthsOfYear\":[\"July\",\"February\",\"May\"],\"retentionScheduleDaily\":{\"daysOfTheMonth\":[{\"date\":217865609,\"isLast\":false}]},\"retentionScheduleWeekly\":{\"daysOfTheWeek\":[\"Sunday\",\"Tuesday\"],\"weeksOfTheMonth\":[\"Last\",\"First\",\"First\"]},\"retentionTimes\":[\"2021-05-28T07:15:32Z\",\"2021-05-30T09:05:45Z\",\"2021-06-08T06:26:04Z\",\"2021-09-14T22:49:23Z\"],\"retentionDuration\":{\"count\":1129614200,\"durationType\":\"Days\"}}")
                .toObject(YearlyRetentionSchedule.class);
        Assertions.assertEquals(RetentionScheduleFormat.WEEKLY, model.retentionScheduleFormatType());
        Assertions.assertEquals(MonthOfYear.JULY, model.monthsOfYear().get(0));
        Assertions.assertEquals(217865609, model.retentionScheduleDaily().daysOfTheMonth().get(0).date());
        Assertions.assertEquals(false, model.retentionScheduleDaily().daysOfTheMonth().get(0).isLast());
        Assertions.assertEquals(DayOfWeek.SUNDAY, model.retentionScheduleWeekly().daysOfTheWeek().get(0));
        Assertions.assertEquals(WeekOfMonth.LAST, model.retentionScheduleWeekly().weeksOfTheMonth().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-28T07:15:32Z"), model.retentionTimes().get(0));
        Assertions.assertEquals(1129614200, model.retentionDuration().count());
        Assertions.assertEquals(RetentionDurationType.DAYS, model.retentionDuration().durationType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        YearlyRetentionSchedule model =
            new YearlyRetentionSchedule()
                .withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
                .withMonthsOfYear(Arrays.asList(MonthOfYear.JULY, MonthOfYear.FEBRUARY, MonthOfYear.MAY))
                .withRetentionScheduleDaily(
                    new DailyRetentionFormat()
                        .withDaysOfTheMonth(Arrays.asList(new Day().withDate(217865609).withIsLast(false))))
                .withRetentionScheduleWeekly(
                    new WeeklyRetentionFormat()
                        .withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY, DayOfWeek.TUESDAY))
                        .withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.LAST, WeekOfMonth.FIRST, WeekOfMonth.FIRST)))
                .withRetentionTimes(
                    Arrays
                        .asList(
                            OffsetDateTime.parse("2021-05-28T07:15:32Z"),
                            OffsetDateTime.parse("2021-05-30T09:05:45Z"),
                            OffsetDateTime.parse("2021-06-08T06:26:04Z"),
                            OffsetDateTime.parse("2021-09-14T22:49:23Z")))
                .withRetentionDuration(
                    new RetentionDuration().withCount(1129614200).withDurationType(RetentionDurationType.DAYS));
        model = BinaryData.fromObject(model).toObject(YearlyRetentionSchedule.class);
        Assertions.assertEquals(RetentionScheduleFormat.WEEKLY, model.retentionScheduleFormatType());
        Assertions.assertEquals(MonthOfYear.JULY, model.monthsOfYear().get(0));
        Assertions.assertEquals(217865609, model.retentionScheduleDaily().daysOfTheMonth().get(0).date());
        Assertions.assertEquals(false, model.retentionScheduleDaily().daysOfTheMonth().get(0).isLast());
        Assertions.assertEquals(DayOfWeek.SUNDAY, model.retentionScheduleWeekly().daysOfTheWeek().get(0));
        Assertions.assertEquals(WeekOfMonth.LAST, model.retentionScheduleWeekly().weeksOfTheMonth().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-28T07:15:32Z"), model.retentionTimes().get(0));
        Assertions.assertEquals(1129614200, model.retentionDuration().count());
        Assertions.assertEquals(RetentionDurationType.DAYS, model.retentionDuration().durationType());
    }
}
