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

package com.azure.resourcemanager.recoveryservicessiterecovery.implementation;

import com.azure.core.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.recoveryservicessiterecovery.fluent.models.ProtectionContainerInner;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.CreateProtectionContainerInput;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.CreateProtectionContainerInputProperties;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.DiscoverProtectableItemRequest;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.ProtectionContainer;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.ProtectionContainerProperties;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.SwitchProtectionInput;

public final class ProtectionContainerImpl implements ProtectionContainer, ProtectionContainer.Definition {
    private ProtectionContainerInner innerObject;

    private final com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager;

    ProtectionContainerImpl(
        ProtectionContainerInner innerObject,
        com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
    }

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

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

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

    public ProtectionContainerProperties properties() {
        return this.innerModel().properties();
    }

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

    public Region region() {
        return Region.fromName(this.regionName());
    }

    public String regionName() {
        return this.location();
    }

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

    private com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager manager() {
        return this.serviceManager;
    }

    private String resourceName;

    private String resourceGroupName;

    private String fabricName;

    private String protectionContainerName;

    private CreateProtectionContainerInput createCreationInput;

    public ProtectionContainerImpl withExistingReplicationFabric(
        String resourceName, String resourceGroupName, String fabricName) {
        this.resourceName = resourceName;
        this.resourceGroupName = resourceGroupName;
        this.fabricName = fabricName;
        return this;
    }

    public ProtectionContainer create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationProtectionContainers()
                .create(
                    resourceName,
                    resourceGroupName,
                    fabricName,
                    protectionContainerName,
                    createCreationInput,
                    Context.NONE);
        return this;
    }

    public ProtectionContainer create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationProtectionContainers()
                .create(
                    resourceName, resourceGroupName, fabricName, protectionContainerName, createCreationInput, context);
        return this;
    }

    ProtectionContainerImpl(
        String name, com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = new ProtectionContainerInner();
        this.serviceManager = serviceManager;
        this.protectionContainerName = name;
        this.createCreationInput = new CreateProtectionContainerInput();
    }

    public ProtectionContainer refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationProtectionContainers()
                .getWithResponse(resourceName, resourceGroupName, fabricName, protectionContainerName, Context.NONE)
                .getValue();
        return this;
    }

    public ProtectionContainer refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationProtectionContainers()
                .getWithResponse(resourceName, resourceGroupName, fabricName, protectionContainerName, context)
                .getValue();
        return this;
    }

    public ProtectionContainer discoverProtectableItem(DiscoverProtectableItemRequest discoverProtectableItemRequest) {
        return serviceManager
            .replicationProtectionContainers()
            .discoverProtectableItem(
                resourceName, resourceGroupName, fabricName, protectionContainerName, discoverProtectableItemRequest);
    }

    public ProtectionContainer discoverProtectableItem(
        DiscoverProtectableItemRequest discoverProtectableItemRequest, Context context) {
        return serviceManager
            .replicationProtectionContainers()
            .discoverProtectableItem(
                resourceName,
                resourceGroupName,
                fabricName,
                protectionContainerName,
                discoverProtectableItemRequest,
                context);
    }

    public void delete() {
        serviceManager
            .replicationProtectionContainers()
            .delete(resourceName, resourceGroupName, fabricName, protectionContainerName);
    }

    public void delete(Context context) {
        serviceManager
            .replicationProtectionContainers()
            .delete(resourceName, resourceGroupName, fabricName, protectionContainerName, context);
    }

    public ProtectionContainer switchProtection(SwitchProtectionInput switchInput) {
        return serviceManager
            .replicationProtectionContainers()
            .switchProtection(resourceName, resourceGroupName, fabricName, protectionContainerName, switchInput);
    }

    public ProtectionContainer switchProtection(SwitchProtectionInput switchInput, Context context) {
        return serviceManager
            .replicationProtectionContainers()
            .switchProtection(
                resourceName, resourceGroupName, fabricName, protectionContainerName, switchInput, context);
    }

    public ProtectionContainerImpl withProperties(CreateProtectionContainerInputProperties properties) {
        this.createCreationInput.withProperties(properties);
        return this;
    }
}
