// 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.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class WeeklyRetentionScheduleTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WeeklyRetentionSchedule model =
            BinaryData
                .fromString(
                    "{\"daysOfTheWeek\":[\"Sunday\",\"Wednesday\",\"Monday\",\"Monday\"],\"retentionTimes\":[\"2021-09-27T15:40:52Z\"],\"retentionDuration\":{\"count\":731867794,\"durationType\":\"Years\"}}")
                .toObject(WeeklyRetentionSchedule.class);
        Assertions.assertEquals(DayOfWeek.SUNDAY, model.daysOfTheWeek().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-27T15:40:52Z"), model.retentionTimes().get(0));
        Assertions.assertEquals(731867794, model.retentionDuration().count());
        Assertions.assertEquals(RetentionDurationType.YEARS, model.retentionDuration().durationType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WeeklyRetentionSchedule model =
            new WeeklyRetentionSchedule()
                .withDaysOfTheWeek(
                    Arrays.asList(DayOfWeek.SUNDAY, DayOfWeek.WEDNESDAY, DayOfWeek.MONDAY, DayOfWeek.MONDAY))
                .withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-09-27T15:40:52Z")))
                .withRetentionDuration(
                    new RetentionDuration().withCount(731867794).withDurationType(RetentionDurationType.YEARS));
        model = BinaryData.fromObject(model).toObject(WeeklyRetentionSchedule.class);
        Assertions.assertEquals(DayOfWeek.SUNDAY, model.daysOfTheWeek().get(0));
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-27T15:40:52Z"), model.retentionTimes().get(0));
        Assertions.assertEquals(731867794, model.retentionDuration().count());
        Assertions.assertEquals(RetentionDurationType.YEARS, model.retentionDuration().durationType());
    }
}
