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

package com.azure.resourcemanager.paloaltonetworks.ngfw.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.PrefixListResourceInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.PrefixListResource;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.ProvisioningState;
import java.util.Collections;
import java.util.List;

public final class PrefixListResourceImpl
    implements PrefixListResource, PrefixListResource.Definition, PrefixListResource.Update {
    private PrefixListResourceInner innerObject;

    private final com.azure.resourcemanager.paloaltonetworks.ngfw.PaloAltoNetworksNgfwManager serviceManager;

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

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

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

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.paloaltonetworks.ngfw.PaloAltoNetworksNgfwManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String localRulestackName;

    private String name;

    public PrefixListResourceImpl withExistingLocalRulestack(String resourceGroupName, String localRulestackName) {
        this.resourceGroupName = resourceGroupName;
        this.localRulestackName = localRulestackName;
        return this;
    }

    public PrefixListResource create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrefixListLocalRulestacks()
                .createOrUpdate(resourceGroupName, localRulestackName, name, this.innerModel(), Context.NONE);
        return this;
    }

    public PrefixListResource create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrefixListLocalRulestacks()
                .createOrUpdate(resourceGroupName, localRulestackName, name, this.innerModel(), context);
        return this;
    }

    PrefixListResourceImpl(
        String name, com.azure.resourcemanager.paloaltonetworks.ngfw.PaloAltoNetworksNgfwManager serviceManager) {
        this.innerObject = new PrefixListResourceInner();
        this.serviceManager = serviceManager;
        this.name = name;
    }

    public PrefixListResourceImpl update() {
        return this;
    }

    public PrefixListResource apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrefixListLocalRulestacks()
                .createOrUpdate(resourceGroupName, localRulestackName, name, this.innerModel(), Context.NONE);
        return this;
    }

    public PrefixListResource apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrefixListLocalRulestacks()
                .createOrUpdate(resourceGroupName, localRulestackName, name, this.innerModel(), context);
        return this;
    }

    PrefixListResourceImpl(
        PrefixListResourceInner innerObject,
        com.azure.resourcemanager.paloaltonetworks.ngfw.PaloAltoNetworksNgfwManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.localRulestackName = Utils.getValueFromIdByName(innerObject.id(), "localRulestacks");
        this.name = Utils.getValueFromIdByName(innerObject.id(), "prefixlists");
    }

    public PrefixListResource refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrefixListLocalRulestacks()
                .getWithResponse(resourceGroupName, localRulestackName, name, Context.NONE)
                .getValue();
        return this;
    }

    public PrefixListResource refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrefixListLocalRulestacks()
                .getWithResponse(resourceGroupName, localRulestackName, name, context)
                .getValue();
        return this;
    }

    public PrefixListResourceImpl withPrefixList(List<String> prefixList) {
        this.innerModel().withPrefixList(prefixList);
        return this;
    }

    public PrefixListResourceImpl withDescription(String description) {
        this.innerModel().withDescription(description);
        return this;
    }

    public PrefixListResourceImpl withEtag(String etag) {
        this.innerModel().withEtag(etag);
        return this;
    }

    public PrefixListResourceImpl withAuditComment(String auditComment) {
        this.innerModel().withAuditComment(auditComment);
        return this;
    }
}
