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

package com.azure.resourcemanager.mobilenetwork.implementation;

import com.azure.core.util.Context;
import com.azure.resourcemanager.mobilenetwork.fluent.models.PacketCaptureInner;
import com.azure.resourcemanager.mobilenetwork.models.AsyncOperationStatus;
import com.azure.resourcemanager.mobilenetwork.models.PacketCapture;
import com.azure.resourcemanager.mobilenetwork.models.PacketCaptureStatus;
import com.azure.resourcemanager.mobilenetwork.models.ProvisioningState;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;

public final class PacketCaptureImpl implements PacketCapture, PacketCapture.Definition, PacketCapture.Update {
    private PacketCaptureInner innerObject;

    private final com.azure.resourcemanager.mobilenetwork.MobileNetworkManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public ProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

    public PacketCaptureStatus status() {
        return this.innerModel().status();
    }

    public String reason() {
        return this.innerModel().reason();
    }

    public OffsetDateTime captureStartTime() {
        return this.innerModel().captureStartTime();
    }

    public List<String> networkInterfaces() {
        List<String> inner = this.innerModel().networkInterfaces();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public Long bytesToCapturePerPacket() {
        return this.innerModel().bytesToCapturePerPacket();
    }

    public Long totalBytesPerSession() {
        return this.innerModel().totalBytesPerSession();
    }

    public Integer timeLimitInSeconds() {
        return this.innerModel().timeLimitInSeconds();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public PacketCaptureInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.mobilenetwork.MobileNetworkManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String packetCoreControlPlaneName;

    private String packetCaptureName;

    public PacketCaptureImpl withExistingPacketCoreControlPlane(
        String resourceGroupName, String packetCoreControlPlaneName) {
        this.resourceGroupName = resourceGroupName;
        this.packetCoreControlPlaneName = packetCoreControlPlaneName;
        return this;
    }

    public PacketCapture create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPacketCaptures()
                .createOrUpdate(
                    resourceGroupName, packetCoreControlPlaneName, packetCaptureName, this.innerModel(), Context.NONE);
        return this;
    }

    public PacketCapture create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPacketCaptures()
                .createOrUpdate(
                    resourceGroupName, packetCoreControlPlaneName, packetCaptureName, this.innerModel(), context);
        return this;
    }

    PacketCaptureImpl(String name, com.azure.resourcemanager.mobilenetwork.MobileNetworkManager serviceManager) {
        this.innerObject = new PacketCaptureInner();
        this.serviceManager = serviceManager;
        this.packetCaptureName = name;
    }

    public PacketCaptureImpl update() {
        return this;
    }

    public PacketCapture apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPacketCaptures()
                .createOrUpdate(
                    resourceGroupName, packetCoreControlPlaneName, packetCaptureName, this.innerModel(), Context.NONE);
        return this;
    }

    public PacketCapture apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPacketCaptures()
                .createOrUpdate(
                    resourceGroupName, packetCoreControlPlaneName, packetCaptureName, this.innerModel(), context);
        return this;
    }

    PacketCaptureImpl(
        PacketCaptureInner innerObject, com.azure.resourcemanager.mobilenetwork.MobileNetworkManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.packetCoreControlPlaneName = Utils.getValueFromIdByName(innerObject.id(), "packetCoreControlPlanes");
        this.packetCaptureName = Utils.getValueFromIdByName(innerObject.id(), "packetCaptures");
    }

    public PacketCapture refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPacketCaptures()
                .getWithResponse(resourceGroupName, packetCoreControlPlaneName, packetCaptureName, Context.NONE)
                .getValue();
        return this;
    }

    public PacketCapture refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPacketCaptures()
                .getWithResponse(resourceGroupName, packetCoreControlPlaneName, packetCaptureName, context)
                .getValue();
        return this;
    }

    public AsyncOperationStatus stop() {
        return serviceManager.packetCaptures().stop(resourceGroupName, packetCoreControlPlaneName, packetCaptureName);
    }

    public AsyncOperationStatus stop(Context context) {
        return serviceManager
            .packetCaptures()
            .stop(resourceGroupName, packetCoreControlPlaneName, packetCaptureName, context);
    }

    public PacketCaptureImpl withNetworkInterfaces(List<String> networkInterfaces) {
        this.innerModel().withNetworkInterfaces(networkInterfaces);
        return this;
    }

    public PacketCaptureImpl withBytesToCapturePerPacket(Long bytesToCapturePerPacket) {
        this.innerModel().withBytesToCapturePerPacket(bytesToCapturePerPacket);
        return this;
    }

    public PacketCaptureImpl withTotalBytesPerSession(Long totalBytesPerSession) {
        this.innerModel().withTotalBytesPerSession(totalBytesPerSession);
        return this;
    }

    public PacketCaptureImpl withTimeLimitInSeconds(Integer timeLimitInSeconds) {
        this.innerModel().withTimeLimitInSeconds(timeLimitInSeconds);
        return this;
    }
}
