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

package com.azure.resourcemanager.netapp.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.netapp.fluent.models.SnapshotPolicyInner;
import com.azure.resourcemanager.netapp.models.DailySchedule;
import com.azure.resourcemanager.netapp.models.HourlySchedule;
import com.azure.resourcemanager.netapp.models.MonthlySchedule;
import com.azure.resourcemanager.netapp.models.WeeklySchedule;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SnapshotPolicyInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SnapshotPolicyInner model =
            BinaryData
                .fromString(
                    "{\"etag\":\"dtmhrkwofyyvoqa\",\"properties\":{\"hourlySchedule\":{\"snapshotsToKeep\":1486476697,\"minute\":837458643,\"usedBytes\":1588065972663705215},\"dailySchedule\":{\"snapshotsToKeep\":670183300,\"hour\":1911820344,\"minute\":2105060368,\"usedBytes\":5468231860855854569},\"weeklySchedule\":{\"snapshotsToKeep\":1437080667,\"day\":\"tkcnqxwb\",\"hour\":924351225,\"minute\":2012667372,\"usedBytes\":5707202889292911189},\"monthlySchedule\":{\"snapshotsToKeep\":1772215321,\"daysOfMonth\":\"sipqii\",\"hour\":675446410,\"minute\":549865384,\"usedBytes\":5255537493272573987},\"enabled\":false,\"provisioningState\":\"qwcciuqg\"},\"location\":\"butauvfb\",\"tags\":{\"afnn\":\"whhmhykojo\",\"ymkcdyhb\":\"lpichk\",\"ovljxywsu\":\"kkpwdreqnovvq\",\"aeneqnzarrwl\":\"syrsndsytgadgvra\"},\"id\":\"uu\",\"name\":\"jfqka\",\"type\":\"e\"}")
                .toObject(SnapshotPolicyInner.class);
        Assertions.assertEquals("butauvfb", model.location());
        Assertions.assertEquals("whhmhykojo", model.tags().get("afnn"));
        Assertions.assertEquals(1486476697, model.hourlySchedule().snapshotsToKeep());
        Assertions.assertEquals(837458643, model.hourlySchedule().minute());
        Assertions.assertEquals(1588065972663705215L, model.hourlySchedule().usedBytes());
        Assertions.assertEquals(670183300, model.dailySchedule().snapshotsToKeep());
        Assertions.assertEquals(1911820344, model.dailySchedule().hour());
        Assertions.assertEquals(2105060368, model.dailySchedule().minute());
        Assertions.assertEquals(5468231860855854569L, model.dailySchedule().usedBytes());
        Assertions.assertEquals(1437080667, model.weeklySchedule().snapshotsToKeep());
        Assertions.assertEquals("tkcnqxwb", model.weeklySchedule().day());
        Assertions.assertEquals(924351225, model.weeklySchedule().hour());
        Assertions.assertEquals(2012667372, model.weeklySchedule().minute());
        Assertions.assertEquals(5707202889292911189L, model.weeklySchedule().usedBytes());
        Assertions.assertEquals(1772215321, model.monthlySchedule().snapshotsToKeep());
        Assertions.assertEquals("sipqii", model.monthlySchedule().daysOfMonth());
        Assertions.assertEquals(675446410, model.monthlySchedule().hour());
        Assertions.assertEquals(549865384, model.monthlySchedule().minute());
        Assertions.assertEquals(5255537493272573987L, model.monthlySchedule().usedBytes());
        Assertions.assertEquals(false, model.enabled());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SnapshotPolicyInner model =
            new SnapshotPolicyInner()
                .withLocation("butauvfb")
                .withTags(
                    mapOf(
                        "afnn",
                        "whhmhykojo",
                        "ymkcdyhb",
                        "lpichk",
                        "ovljxywsu",
                        "kkpwdreqnovvq",
                        "aeneqnzarrwl",
                        "syrsndsytgadgvra"))
                .withHourlySchedule(
                    new HourlySchedule()
                        .withSnapshotsToKeep(1486476697)
                        .withMinute(837458643)
                        .withUsedBytes(1588065972663705215L))
                .withDailySchedule(
                    new DailySchedule()
                        .withSnapshotsToKeep(670183300)
                        .withHour(1911820344)
                        .withMinute(2105060368)
                        .withUsedBytes(5468231860855854569L))
                .withWeeklySchedule(
                    new WeeklySchedule()
                        .withSnapshotsToKeep(1437080667)
                        .withDay("tkcnqxwb")
                        .withHour(924351225)
                        .withMinute(2012667372)
                        .withUsedBytes(5707202889292911189L))
                .withMonthlySchedule(
                    new MonthlySchedule()
                        .withSnapshotsToKeep(1772215321)
                        .withDaysOfMonth("sipqii")
                        .withHour(675446410)
                        .withMinute(549865384)
                        .withUsedBytes(5255537493272573987L))
                .withEnabled(false);
        model = BinaryData.fromObject(model).toObject(SnapshotPolicyInner.class);
        Assertions.assertEquals("butauvfb", model.location());
        Assertions.assertEquals("whhmhykojo", model.tags().get("afnn"));
        Assertions.assertEquals(1486476697, model.hourlySchedule().snapshotsToKeep());
        Assertions.assertEquals(837458643, model.hourlySchedule().minute());
        Assertions.assertEquals(1588065972663705215L, model.hourlySchedule().usedBytes());
        Assertions.assertEquals(670183300, model.dailySchedule().snapshotsToKeep());
        Assertions.assertEquals(1911820344, model.dailySchedule().hour());
        Assertions.assertEquals(2105060368, model.dailySchedule().minute());
        Assertions.assertEquals(5468231860855854569L, model.dailySchedule().usedBytes());
        Assertions.assertEquals(1437080667, model.weeklySchedule().snapshotsToKeep());
        Assertions.assertEquals("tkcnqxwb", model.weeklySchedule().day());
        Assertions.assertEquals(924351225, model.weeklySchedule().hour());
        Assertions.assertEquals(2012667372, model.weeklySchedule().minute());
        Assertions.assertEquals(5707202889292911189L, model.weeklySchedule().usedBytes());
        Assertions.assertEquals(1772215321, model.monthlySchedule().snapshotsToKeep());
        Assertions.assertEquals("sipqii", model.monthlySchedule().daysOfMonth());
        Assertions.assertEquals(675446410, model.monthlySchedule().hour());
        Assertions.assertEquals(549865384, model.monthlySchedule().minute());
        Assertions.assertEquals(5255537493272573987L, model.monthlySchedule().usedBytes());
        Assertions.assertEquals(false, model.enabled());
    }

    @SuppressWarnings("unchecked")
    private static <T> Map<String, T> mapOf(Object... inputs) {
        Map<String, T> map = new HashMap<>();
        for (int i = 0; i < inputs.length; i += 2) {
            String key = (String) inputs[i];
            T value = (T) inputs[i + 1];
            map.put(key, value);
        }
        return map;
    }
}
