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

package com.azure.resourcemanager.videoanalyzer.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.videoanalyzer.fluent.models.AccessPolicyEntityInner;
import com.azure.resourcemanager.videoanalyzer.models.AccessPolicyEntity;
import com.azure.resourcemanager.videoanalyzer.models.AccessPolicyRole;
import com.azure.resourcemanager.videoanalyzer.models.AuthenticationBase;

public final class AccessPolicyEntityImpl
    implements AccessPolicyEntity, AccessPolicyEntity.Definition, AccessPolicyEntity.Update {
    private AccessPolicyEntityInner innerObject;

    private final com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager 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 AccessPolicyRole role() {
        return this.innerModel().role();
    }

    public AuthenticationBase authentication() {
        return this.innerModel().authentication();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String accountName;

    private String accessPolicyName;

    public AccessPolicyEntityImpl withExistingVideoAnalyzer(String resourceGroupName, String accountName) {
        this.resourceGroupName = resourceGroupName;
        this.accountName = accountName;
        return this;
    }

    public AccessPolicyEntity create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAccessPolicies()
                .createOrUpdateWithResponse(
                    resourceGroupName, accountName, accessPolicyName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public AccessPolicyEntity create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAccessPolicies()
                .createOrUpdateWithResponse(
                    resourceGroupName, accountName, accessPolicyName, this.innerModel(), context)
                .getValue();
        return this;
    }

    AccessPolicyEntityImpl(String name, com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager serviceManager) {
        this.innerObject = new AccessPolicyEntityInner();
        this.serviceManager = serviceManager;
        this.accessPolicyName = name;
    }

    public AccessPolicyEntityImpl update() {
        return this;
    }

    public AccessPolicyEntity apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAccessPolicies()
                .updateWithResponse(resourceGroupName, accountName, accessPolicyName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public AccessPolicyEntity apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAccessPolicies()
                .updateWithResponse(resourceGroupName, accountName, accessPolicyName, this.innerModel(), context)
                .getValue();
        return this;
    }

    AccessPolicyEntityImpl(
        AccessPolicyEntityInner innerObject,
        com.azure.resourcemanager.videoanalyzer.VideoAnalyzerManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.accountName = Utils.getValueFromIdByName(innerObject.id(), "videoAnalyzers");
        this.accessPolicyName = Utils.getValueFromIdByName(innerObject.id(), "accessPolicies");
    }

    public AccessPolicyEntity refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAccessPolicies()
                .getWithResponse(resourceGroupName, accountName, accessPolicyName, Context.NONE)
                .getValue();
        return this;
    }

    public AccessPolicyEntity refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getAccessPolicies()
                .getWithResponse(resourceGroupName, accountName, accessPolicyName, context)
                .getValue();
        return this;
    }

    public AccessPolicyEntityImpl withRole(AccessPolicyRole role) {
        this.innerModel().withRole(role);
        return this;
    }

    public AccessPolicyEntityImpl withAuthentication(AuthenticationBase authentication) {
        this.innerModel().withAuthentication(authentication);
        return this;
    }
}
