// 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.RecoveryPlanInner;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.CreateRecoveryPlanInput;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.CreateRecoveryPlanInputProperties;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.RecoveryPlan;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.RecoveryPlanPlannedFailoverInput;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.RecoveryPlanProperties;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.RecoveryPlanTestFailoverCleanupInput;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.RecoveryPlanTestFailoverInput;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.RecoveryPlanUnplannedFailoverInput;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.UpdateRecoveryPlanInput;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.UpdateRecoveryPlanInputProperties;

public final class RecoveryPlanImpl implements RecoveryPlan, RecoveryPlan.Definition, RecoveryPlan.Update {
    private RecoveryPlanInner innerObject;

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

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

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

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

    public RecoveryPlanProperties 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 String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceName;

    private String resourceGroupName;

    private String recoveryPlanName;

    private CreateRecoveryPlanInput createInput;

    private UpdateRecoveryPlanInput updateInput;

    public RecoveryPlanImpl withExistingVault(String resourceName, String resourceGroupName) {
        this.resourceName = resourceName;
        this.resourceGroupName = resourceGroupName;
        return this;
    }

    public RecoveryPlan create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationRecoveryPlans()
                .create(resourceName, resourceGroupName, recoveryPlanName, createInput, Context.NONE);
        return this;
    }

    public RecoveryPlan create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationRecoveryPlans()
                .create(resourceName, resourceGroupName, recoveryPlanName, createInput, context);
        return this;
    }

    RecoveryPlanImpl(
        String name, com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = new RecoveryPlanInner();
        this.serviceManager = serviceManager;
        this.recoveryPlanName = name;
        this.createInput = new CreateRecoveryPlanInput();
    }

    public RecoveryPlanImpl update() {
        this.updateInput = new UpdateRecoveryPlanInput();
        return this;
    }

    public RecoveryPlan apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationRecoveryPlans()
                .update(resourceName, resourceGroupName, recoveryPlanName, updateInput, Context.NONE);
        return this;
    }

    public RecoveryPlan apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationRecoveryPlans()
                .update(resourceName, resourceGroupName, recoveryPlanName, updateInput, context);
        return this;
    }

    RecoveryPlanImpl(
        RecoveryPlanInner innerObject,
        com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceName = Utils.getValueFromIdByName(innerObject.id(), "vaults");
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.recoveryPlanName = Utils.getValueFromIdByName(innerObject.id(), "replicationRecoveryPlans");
    }

    public RecoveryPlan refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationRecoveryPlans()
                .getWithResponse(resourceName, resourceGroupName, recoveryPlanName, Context.NONE)
                .getValue();
        return this;
    }

    public RecoveryPlan refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationRecoveryPlans()
                .getWithResponse(resourceName, resourceGroupName, recoveryPlanName, context)
                .getValue();
        return this;
    }

    public RecoveryPlan failoverCancel() {
        return serviceManager
            .replicationRecoveryPlans()
            .failoverCancel(resourceName, resourceGroupName, recoveryPlanName);
    }

    public RecoveryPlan failoverCancel(Context context) {
        return serviceManager
            .replicationRecoveryPlans()
            .failoverCancel(resourceName, resourceGroupName, recoveryPlanName, context);
    }

    public RecoveryPlan failoverCommit() {
        return serviceManager
            .replicationRecoveryPlans()
            .failoverCommit(resourceName, resourceGroupName, recoveryPlanName);
    }

    public RecoveryPlan failoverCommit(Context context) {
        return serviceManager
            .replicationRecoveryPlans()
            .failoverCommit(resourceName, resourceGroupName, recoveryPlanName, context);
    }

    public RecoveryPlan plannedFailover(RecoveryPlanPlannedFailoverInput input) {
        return serviceManager
            .replicationRecoveryPlans()
            .plannedFailover(resourceName, resourceGroupName, recoveryPlanName, input);
    }

    public RecoveryPlan plannedFailover(RecoveryPlanPlannedFailoverInput input, Context context) {
        return serviceManager
            .replicationRecoveryPlans()
            .plannedFailover(resourceName, resourceGroupName, recoveryPlanName, input, context);
    }

    public RecoveryPlan reprotect() {
        return serviceManager.replicationRecoveryPlans().reprotect(resourceName, resourceGroupName, recoveryPlanName);
    }

    public RecoveryPlan reprotect(Context context) {
        return serviceManager
            .replicationRecoveryPlans()
            .reprotect(resourceName, resourceGroupName, recoveryPlanName, context);
    }

    public RecoveryPlan testFailover(RecoveryPlanTestFailoverInput input) {
        return serviceManager
            .replicationRecoveryPlans()
            .testFailover(resourceName, resourceGroupName, recoveryPlanName, input);
    }

    public RecoveryPlan testFailover(RecoveryPlanTestFailoverInput input, Context context) {
        return serviceManager
            .replicationRecoveryPlans()
            .testFailover(resourceName, resourceGroupName, recoveryPlanName, input, context);
    }

    public RecoveryPlan testFailoverCleanup(RecoveryPlanTestFailoverCleanupInput input) {
        return serviceManager
            .replicationRecoveryPlans()
            .testFailoverCleanup(resourceName, resourceGroupName, recoveryPlanName, input);
    }

    public RecoveryPlan testFailoverCleanup(RecoveryPlanTestFailoverCleanupInput input, Context context) {
        return serviceManager
            .replicationRecoveryPlans()
            .testFailoverCleanup(resourceName, resourceGroupName, recoveryPlanName, input, context);
    }

    public RecoveryPlan unplannedFailover(RecoveryPlanUnplannedFailoverInput input) {
        return serviceManager
            .replicationRecoveryPlans()
            .unplannedFailover(resourceName, resourceGroupName, recoveryPlanName, input);
    }

    public RecoveryPlan unplannedFailover(RecoveryPlanUnplannedFailoverInput input, Context context) {
        return serviceManager
            .replicationRecoveryPlans()
            .unplannedFailover(resourceName, resourceGroupName, recoveryPlanName, input, context);
    }

    public RecoveryPlanImpl withProperties(CreateRecoveryPlanInputProperties properties) {
        this.createInput.withProperties(properties);
        return this;
    }

    public RecoveryPlanImpl withProperties(UpdateRecoveryPlanInputProperties properties) {
        this.updateInput.withProperties(properties);
        return this;
    }
}
