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

package com.azure.resourcemanager.policyinsights.implementation;

import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.policyinsights.fluent.models.RemediationInner;
import com.azure.resourcemanager.policyinsights.models.Remediation;
import com.azure.resourcemanager.policyinsights.models.RemediationDeployment;
import com.azure.resourcemanager.policyinsights.models.RemediationDeploymentSummary;
import com.azure.resourcemanager.policyinsights.models.RemediationFilters;
import com.azure.resourcemanager.policyinsights.models.RemediationPropertiesFailureThreshold;
import com.azure.resourcemanager.policyinsights.models.ResourceDiscoveryMode;
import java.time.OffsetDateTime;

public final class RemediationImpl implements Remediation, Remediation.Definition, Remediation.Update {
    private RemediationInner innerObject;

    private final com.azure.resourcemanager.policyinsights.PolicyInsightsManager 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 policyAssignmentId() {
        return this.innerModel().policyAssignmentId();
    }

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

    public ResourceDiscoveryMode resourceDiscoveryMode() {
        return this.innerModel().resourceDiscoveryMode();
    }

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

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

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

    public RemediationFilters filters() {
        return this.innerModel().filters();
    }

    public RemediationDeploymentSummary deploymentStatus() {
        return this.innerModel().deploymentStatus();
    }

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

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

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

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

    public RemediationPropertiesFailureThreshold failureThreshold() {
        return this.innerModel().failureThreshold();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.policyinsights.PolicyInsightsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String remediationName;

    public RemediationImpl withExistingResourceGroup(String resourceGroupName) {
        this.resourceGroupName = resourceGroupName;
        return this;
    }

    public Remediation create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRemediations()
                .createOrUpdateAtResourceGroupWithResponse(
                    resourceGroupName, remediationName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Remediation create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRemediations()
                .createOrUpdateAtResourceGroupWithResponse(
                    resourceGroupName, remediationName, this.innerModel(), context)
                .getValue();
        return this;
    }

    RemediationImpl(String name, com.azure.resourcemanager.policyinsights.PolicyInsightsManager serviceManager) {
        this.innerObject = new RemediationInner();
        this.serviceManager = serviceManager;
        this.remediationName = name;
    }

    public RemediationImpl update() {
        return this;
    }

    public Remediation apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRemediations()
                .createOrUpdateAtResourceGroupWithResponse(
                    resourceGroupName, remediationName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Remediation apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRemediations()
                .createOrUpdateAtResourceGroupWithResponse(
                    resourceGroupName, remediationName, this.innerModel(), context)
                .getValue();
        return this;
    }

    RemediationImpl(
        RemediationInner innerObject, com.azure.resourcemanager.policyinsights.PolicyInsightsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.remediationName = Utils.getValueFromIdByName(innerObject.id(), "remediations");
    }

    public Remediation refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRemediations()
                .getByResourceGroupWithResponse(resourceGroupName, remediationName, Context.NONE)
                .getValue();
        return this;
    }

    public Remediation refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getRemediations()
                .getByResourceGroupWithResponse(resourceGroupName, remediationName, context)
                .getValue();
        return this;
    }

    public PagedIterable<RemediationDeployment> listDeploymentsAtResourceGroup() {
        return serviceManager.remediations().listDeploymentsAtResourceGroup(resourceGroupName, remediationName);
    }

    public PagedIterable<RemediationDeployment> listDeploymentsAtResourceGroup(Integer top, Context context) {
        return serviceManager
            .remediations()
            .listDeploymentsAtResourceGroup(resourceGroupName, remediationName, top, context);
    }

    public Response<Remediation> cancelAtResourceGroupWithResponse(Context context) {
        return serviceManager
            .remediations()
            .cancelAtResourceGroupWithResponse(resourceGroupName, remediationName, context);
    }

    public Remediation cancelAtResourceGroup() {
        return serviceManager.remediations().cancelAtResourceGroup(resourceGroupName, remediationName);
    }

    public RemediationImpl withPolicyAssignmentId(String policyAssignmentId) {
        this.innerModel().withPolicyAssignmentId(policyAssignmentId);
        return this;
    }

    public RemediationImpl withPolicyDefinitionReferenceId(String policyDefinitionReferenceId) {
        this.innerModel().withPolicyDefinitionReferenceId(policyDefinitionReferenceId);
        return this;
    }

    public RemediationImpl withResourceDiscoveryMode(ResourceDiscoveryMode resourceDiscoveryMode) {
        this.innerModel().withResourceDiscoveryMode(resourceDiscoveryMode);
        return this;
    }

    public RemediationImpl withFilters(RemediationFilters filters) {
        this.innerModel().withFilters(filters);
        return this;
    }

    public RemediationImpl withResourceCount(Integer resourceCount) {
        this.innerModel().withResourceCount(resourceCount);
        return this;
    }

    public RemediationImpl withParallelDeployments(Integer parallelDeployments) {
        this.innerModel().withParallelDeployments(parallelDeployments);
        return this;
    }

    public RemediationImpl withFailureThreshold(RemediationPropertiesFailureThreshold failureThreshold) {
        this.innerModel().withFailureThreshold(failureThreshold);
        return this;
    }
}
