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

package com.azure.resourcemanager.mediaservices.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.mediaservices.fluent.models.TransformInner;
import com.azure.resourcemanager.mediaservices.models.Transform;
import com.azure.resourcemanager.mediaservices.models.TransformOutput;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;

public final class TransformImpl implements Transform, Transform.Definition, Transform.Update {
    private TransformInner innerObject;

    private final com.azure.resourcemanager.mediaservices.MediaServicesManager 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 OffsetDateTime created() {
        return this.innerModel().created();
    }

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.mediaservices.MediaServicesManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String accountName;

    private String transformName;

    public TransformImpl withExistingMediaService(String resourceGroupName, String accountName) {
        this.resourceGroupName = resourceGroupName;
        this.accountName = accountName;
        return this;
    }

    public Transform create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTransforms()
                .createOrUpdateWithResponse(
                    resourceGroupName, accountName, transformName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Transform create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTransforms()
                .createOrUpdateWithResponse(resourceGroupName, accountName, transformName, this.innerModel(), context)
                .getValue();
        return this;
    }

    TransformImpl(String name, com.azure.resourcemanager.mediaservices.MediaServicesManager serviceManager) {
        this.innerObject = new TransformInner();
        this.serviceManager = serviceManager;
        this.transformName = name;
    }

    public TransformImpl update() {
        return this;
    }

    public Transform apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTransforms()
                .updateWithResponse(resourceGroupName, accountName, transformName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Transform apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTransforms()
                .updateWithResponse(resourceGroupName, accountName, transformName, this.innerModel(), context)
                .getValue();
        return this;
    }

    TransformImpl(
        TransformInner innerObject, com.azure.resourcemanager.mediaservices.MediaServicesManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.accountName = Utils.getValueFromIdByName(innerObject.id(), "mediaServices");
        this.transformName = Utils.getValueFromIdByName(innerObject.id(), "transforms");
    }

    public Transform refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTransforms()
                .getWithResponse(resourceGroupName, accountName, transformName, Context.NONE)
                .getValue();
        return this;
    }

    public Transform refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTransforms()
                .getWithResponse(resourceGroupName, accountName, transformName, context)
                .getValue();
        return this;
    }

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

    public TransformImpl withOutputs(List<TransformOutput> outputs) {
        this.innerModel().withOutputs(outputs);
        return this;
    }
}
