// 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.MonthlyRetentionSchedule;
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 java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class MonthlyRetentionScheduleTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        MonthlyRetentionSchedule model =
            BinaryData
                .fromString(
                    "{\"retentionScheduleFormatType\":\"Daily\",\"retentionScheduleDaily\":{\"daysOfTheMonth\":[{\"date\":1575805762,\"isLast\":false},{\"date\":1040750997,\"isLast\":true},{\"date\":800283877,\"isLast\":false}]},\"retentionScheduleWeekly\":{\"daysOfTheWeek\":[\"Monday\",\"Tuesday\"],\"weeksOfTheMonth\":[\"Third\",\"First\",\"First\",\"Invalid\"]},\"retentionTimes\":[\"2021-05-15T22:31:41Z\",\"2021-09-12T02:04:13Z\"],\"retentionDuration\":{\"count\":347031598,\"durationType\":\"Invalid\"}}")
                .toObject(MonthlyRetentionSchedule.class);
        Assertions.assertEquals(RetentionScheduleFormat.DAILY, model.retentionScheduleFormatType());
        Assertions.assertEquals(1575805762, model.retentionScheduleDaily().daysOfTheMonth().get(0).date());
        Assertions.assertEquals(false, model.retentionScheduleDaily().daysOfTheMonth().get(0).isLast());
        Assertions.assertEquals(DayOfWeek.MONDAY, model.retentionScheduleWeekly().daysOfTheWeek().get(0));
        Assertions.assertEquals(WeekOfMonth.THIRD, model.retentionScheduleWeekly().weeksOfTheMonth().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-15T22:31:41Z"), model.retentionTimes().get(0));
        Assertions.assertEquals(347031598, model.retentionDuration().count());
        Assertions.assertEquals(RetentionDurationType.INVALID, model.retentionDuration().durationType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        MonthlyRetentionSchedule model =
            new MonthlyRetentionSchedule()
                .withRetentionScheduleFormatType(RetentionScheduleFormat.DAILY)
                .withRetentionScheduleDaily(
                    new DailyRetentionFormat()
                        .withDaysOfTheMonth(
                            Arrays
                                .asList(
                                    new Day().withDate(1575805762).withIsLast(false),
                                    new Day().withDate(1040750997).withIsLast(true),
                                    new Day().withDate(800283877).withIsLast(false))))
                .withRetentionScheduleWeekly(
                    new WeeklyRetentionFormat()
                        .withDaysOfTheWeek(Arrays.asList(DayOfWeek.MONDAY, DayOfWeek.TUESDAY))
                        .withWeeksOfTheMonth(
                            Arrays
                                .asList(WeekOfMonth.THIRD, WeekOfMonth.FIRST, WeekOfMonth.FIRST, WeekOfMonth.INVALID)))
                .withRetentionTimes(
                    Arrays
                        .asList(
                            OffsetDateTime.parse("2021-05-15T22:31:41Z"), OffsetDateTime.parse("2021-09-12T02:04:13Z")))
                .withRetentionDuration(
                    new RetentionDuration().withCount(347031598).withDurationType(RetentionDurationType.INVALID));
        model = BinaryData.fromObject(model).toObject(MonthlyRetentionSchedule.class);
        Assertions.assertEquals(RetentionScheduleFormat.DAILY, model.retentionScheduleFormatType());
        Assertions.assertEquals(1575805762, model.retentionScheduleDaily().daysOfTheMonth().get(0).date());
        Assertions.assertEquals(false, model.retentionScheduleDaily().daysOfTheMonth().get(0).isLast());
        Assertions.assertEquals(DayOfWeek.MONDAY, model.retentionScheduleWeekly().daysOfTheWeek().get(0));
        Assertions.assertEquals(WeekOfMonth.THIRD, model.retentionScheduleWeekly().weeksOfTheMonth().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-15T22:31:41Z"), model.retentionTimes().get(0));
        Assertions.assertEquals(347031598, model.retentionDuration().count());
        Assertions.assertEquals(RetentionDurationType.INVALID, model.retentionDuration().durationType());
    }
}
