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

package com.azure.resourcemanager.mediaservices.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.mediaservices.models.Deinterlace;
import com.azure.resourcemanager.mediaservices.models.DeinterlaceMode;
import com.azure.resourcemanager.mediaservices.models.DeinterlaceParity;
import com.azure.resourcemanager.mediaservices.models.Fade;
import com.azure.resourcemanager.mediaservices.models.Filters;
import com.azure.resourcemanager.mediaservices.models.Overlay;
import com.azure.resourcemanager.mediaservices.models.Rectangle;
import com.azure.resourcemanager.mediaservices.models.Rotation;
import java.time.Duration;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class FiltersTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        Filters model =
            BinaryData
                .fromString(
                    "{\"deinterlace\":{\"parity\":\"TopFieldFirst\",\"mode\":\"Off\"},\"rotation\":\"Auto\",\"crop\":{\"left\":\"n\",\"top\":\"b\",\"width\":\"ajlyjtlvofqzhv\",\"height\":\"ibyfmo\"},\"fadeIn\":{\"duration\":\"PT43H27M36S\",\"fadeColor\":\"rkjpvdwxfzwii\",\"start\":\"zjb\"},\"fadeOut\":{\"duration\":\"PT179H3M48S\",\"fadeColor\":\"sxjrk\",\"start\":\"btrnegvm\"},\"overlays\":[{\"@odata.type\":\"Overlay\",\"inputLabel\":\"q\",\"start\":\"PT195H49M26S\",\"end\":\"PT87H42M49S\",\"fadeInDuration\":\"PT56H46M12S\",\"fadeOutDuration\":\"PT100H47M46S\",\"audioGainLevel\":92.57189513687753},{\"@odata.type\":\"Overlay\",\"inputLabel\":\"kkdmfl\",\"start\":\"PT69H46M52S\",\"end\":\"PT61H27M7S\",\"fadeInDuration\":\"PT42H3M53S\",\"fadeOutDuration\":\"PT36H32M49S\",\"audioGainLevel\":92.17159130081457}]}")
                .toObject(Filters.class);
        Assertions.assertEquals(DeinterlaceParity.TOP_FIELD_FIRST, model.deinterlace().parity());
        Assertions.assertEquals(DeinterlaceMode.OFF, model.deinterlace().mode());
        Assertions.assertEquals(Rotation.AUTO, model.rotation());
        Assertions.assertEquals("n", model.crop().left());
        Assertions.assertEquals("b", model.crop().top());
        Assertions.assertEquals("ajlyjtlvofqzhv", model.crop().width());
        Assertions.assertEquals("ibyfmo", model.crop().height());
        Assertions.assertEquals(Duration.parse("PT43H27M36S"), model.fadeIn().duration());
        Assertions.assertEquals("rkjpvdwxfzwii", model.fadeIn().fadeColor());
        Assertions.assertEquals("zjb", model.fadeIn().start());
        Assertions.assertEquals(Duration.parse("PT179H3M48S"), model.fadeOut().duration());
        Assertions.assertEquals("sxjrk", model.fadeOut().fadeColor());
        Assertions.assertEquals("btrnegvm", model.fadeOut().start());
        Assertions.assertEquals("q", model.overlays().get(0).inputLabel());
        Assertions.assertEquals(Duration.parse("PT195H49M26S"), model.overlays().get(0).start());
        Assertions.assertEquals(Duration.parse("PT87H42M49S"), model.overlays().get(0).end());
        Assertions.assertEquals(Duration.parse("PT56H46M12S"), model.overlays().get(0).fadeInDuration());
        Assertions.assertEquals(Duration.parse("PT100H47M46S"), model.overlays().get(0).fadeOutDuration());
        Assertions.assertEquals(92.57189513687753D, model.overlays().get(0).audioGainLevel());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        Filters model =
            new Filters()
                .withDeinterlace(
                    new Deinterlace().withParity(DeinterlaceParity.TOP_FIELD_FIRST).withMode(DeinterlaceMode.OFF))
                .withRotation(Rotation.AUTO)
                .withCrop(new Rectangle().withLeft("n").withTop("b").withWidth("ajlyjtlvofqzhv").withHeight("ibyfmo"))
                .withFadeIn(
                    new Fade()
                        .withDuration(Duration.parse("PT43H27M36S"))
                        .withFadeColor("rkjpvdwxfzwii")
                        .withStart("zjb"))
                .withFadeOut(
                    new Fade().withDuration(Duration.parse("PT179H3M48S")).withFadeColor("sxjrk").withStart("btrnegvm"))
                .withOverlays(
                    Arrays
                        .asList(
                            new Overlay()
                                .withInputLabel("q")
                                .withStart(Duration.parse("PT195H49M26S"))
                                .withEnd(Duration.parse("PT87H42M49S"))
                                .withFadeInDuration(Duration.parse("PT56H46M12S"))
                                .withFadeOutDuration(Duration.parse("PT100H47M46S"))
                                .withAudioGainLevel(92.57189513687753D),
                            new Overlay()
                                .withInputLabel("kkdmfl")
                                .withStart(Duration.parse("PT69H46M52S"))
                                .withEnd(Duration.parse("PT61H27M7S"))
                                .withFadeInDuration(Duration.parse("PT42H3M53S"))
                                .withFadeOutDuration(Duration.parse("PT36H32M49S"))
                                .withAudioGainLevel(92.17159130081457D)));
        model = BinaryData.fromObject(model).toObject(Filters.class);
        Assertions.assertEquals(DeinterlaceParity.TOP_FIELD_FIRST, model.deinterlace().parity());
        Assertions.assertEquals(DeinterlaceMode.OFF, model.deinterlace().mode());
        Assertions.assertEquals(Rotation.AUTO, model.rotation());
        Assertions.assertEquals("n", model.crop().left());
        Assertions.assertEquals("b", model.crop().top());
        Assertions.assertEquals("ajlyjtlvofqzhv", model.crop().width());
        Assertions.assertEquals("ibyfmo", model.crop().height());
        Assertions.assertEquals(Duration.parse("PT43H27M36S"), model.fadeIn().duration());
        Assertions.assertEquals("rkjpvdwxfzwii", model.fadeIn().fadeColor());
        Assertions.assertEquals("zjb", model.fadeIn().start());
        Assertions.assertEquals(Duration.parse("PT179H3M48S"), model.fadeOut().duration());
        Assertions.assertEquals("sxjrk", model.fadeOut().fadeColor());
        Assertions.assertEquals("btrnegvm", model.fadeOut().start());
        Assertions.assertEquals("q", model.overlays().get(0).inputLabel());
        Assertions.assertEquals(Duration.parse("PT195H49M26S"), model.overlays().get(0).start());
        Assertions.assertEquals(Duration.parse("PT87H42M49S"), model.overlays().get(0).end());
        Assertions.assertEquals(Duration.parse("PT56H46M12S"), model.overlays().get(0).fadeInDuration());
        Assertions.assertEquals(Duration.parse("PT100H47M46S"), model.overlays().get(0).fadeOutDuration());
        Assertions.assertEquals(92.57189513687753D, model.overlays().get(0).audioGainLevel());
    }
}
