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

package azure.resourcemanager.operationtemplates.implementation;

import azure.resourcemanager.operationtemplates.fluent.models.OrderInner;
import azure.resourcemanager.operationtemplates.models.ExportRequest;
import azure.resourcemanager.operationtemplates.models.ExportResult;
import azure.resourcemanager.operationtemplates.models.Order;
import azure.resourcemanager.operationtemplates.models.OrderProperties;
import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import java.util.Collections;
import java.util.Map;

public final class OrderImpl implements Order, Order.Definition {
    private OrderInner innerObject;

    private final azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager;

    OrderImpl(OrderInner innerObject,
        azure.resourcemanager.operationtemplates.OperationTemplatesManager 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 String location() {
        return this.innerModel().location();
    }

    public Map<String, String> tags() {
        Map<String, String> inner = this.innerModel().tags();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

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

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

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

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

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

    private azure.resourcemanager.operationtemplates.OperationTemplatesManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String orderName;

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

    public Order create() {
        this.innerObject = serviceManager.serviceClient()
            .getLroes()
            .createOrReplace(resourceGroupName, orderName, this.innerModel(), Context.NONE);
        return this;
    }

    public Order create(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getLroes()
            .createOrReplace(resourceGroupName, orderName, this.innerModel(), context);
        return this;
    }

    OrderImpl(String name, azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager) {
        this.innerObject = new OrderInner();
        this.serviceManager = serviceManager;
        this.orderName = name;
    }

    public ExportResult export(ExportRequest body) {
        return serviceManager.lroes().export(resourceGroupName, orderName, body);
    }

    public ExportResult export(ExportRequest body, Context context) {
        return serviceManager.lroes().export(resourceGroupName, orderName, body, context);
    }

    public OrderImpl withRegion(Region location) {
        this.innerModel().withLocation(location.toString());
        return this;
    }

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

    public OrderImpl withTags(Map<String, String> tags) {
        this.innerModel().withTags(tags);
        return this;
    }

    public OrderImpl withProperties(OrderProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
