// This is an automatically generated code sample. 
// To make this code sample work in your Oracle Cloud tenancy, 
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and 
// boolean, number, and enum parameters with values not fitting your use case).

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Oci.FleetappsmanagementService;
using Oci.Common;
using Oci.Common.Auth;

namespace Oci.Sdk.DotNet.Example.Fleetappsmanagement
{
    public class CreateRunbookExample
    {
        public static async Task Main()
        {
            // Create a request and dependent object(s).
			var createRunbookDetails = new Oci.FleetappsmanagementService.Models.CreateRunbookDetails
			{
				DisplayName = "EXAMPLE-displayName-Value",
				Description = "EXAMPLE-description-Value",
				Operation = "EXAMPLE-operation-Value",
				OsType = Oci.FleetappsmanagementService.Models.OsType.Generic,
				Platform = "EXAMPLE-platform-Value",
				IsDefault = false,
				IsSudoAccessNeeded = false,
				EstimatedTime = "EXAMPLE-estimatedTime-Value",
				RunbookVersion = new Oci.FleetappsmanagementService.Models.Version
				{
					Tasks = new List<Oci.FleetappsmanagementService.Models.Task>
					{
						new Oci.FleetappsmanagementService.Models.Task
						{
							StepName = "EXAMPLE-stepName-Value",
							TaskRecordDetails = new Oci.FleetappsmanagementService.Models.AssociatedSharedTaskDetails
							{
								TaskRecordId = "ocid1.test.oc1..<unique_ID>EXAMPLE-taskRecordId-Value"
							},
							StepProperties = new Oci.FleetappsmanagementService.Models.ComponentProperties
							{
								RunOn = new Oci.FleetappsmanagementService.Models.PreviousTaskInstanceRunOnDetails
								{
									PreviousTaskInstanceDetails = new List<Oci.FleetappsmanagementService.Models.PreviousTaskInstanceDetails>
									{
										new Oci.FleetappsmanagementService.Models.PreviousTaskInstanceDetails
										{
											OutputVariableDetails = new Oci.FleetappsmanagementService.Models.OutputVariableDetails
											{
												StepName = "EXAMPLE-stepName-Value",
												OutputVariableName = "EXAMPLE-outputVariableName-Value"
											},
											ResourceId = "ocid1.test.oc1..<unique_ID>EXAMPLE-resourceId-Value",
											ResourceType = "EXAMPLE-resourceType-Value"
										}
									}
								},
								PreCondition = "EXAMPLE-preCondition-Value",
								ActionOnFailure = Oci.FleetappsmanagementService.Models.ComponentProperties.ActionOnFailureEnum.Rollback,
								PauseDetails = new Oci.FleetappsmanagementService.Models.UserActionBasedPauseDetails
								{
								},
								NotificationPreferences = new Oci.FleetappsmanagementService.Models.TaskNotificationPreferences
								{
									ShouldNotifyOnPause = false,
									ShouldNotifyOnTaskFailure = false,
									ShouldNotifyOnTaskSuccess = true
								}
							},
							OutputVariableMappings = new List<Oci.FleetappsmanagementService.Models.OutputVariableMapping>
							{
								new Oci.FleetappsmanagementService.Models.OutputVariableMapping
								{
									Name = "EXAMPLE-name-Value",
									OutputVariableDetails = new Oci.FleetappsmanagementService.Models.OutputVariableDetails
									{
										StepName = "EXAMPLE-stepName-Value",
										OutputVariableName = "EXAMPLE-outputVariableName-Value"
									}
								}
							}
						}
					},
					Groups = new List<Oci.FleetappsmanagementService.Models.Group>
					{
						new Oci.FleetappsmanagementService.Models.Group
						{
							Type = Oci.FleetappsmanagementService.Models.Group.TypeEnum.RollingResourceGroup,
							Name = "EXAMPLE-name-Value",
							Properties = new Oci.FleetappsmanagementService.Models.ComponentProperties
							{
								RunOn = new Oci.FleetappsmanagementService.Models.PreviousTaskInstanceRunOnDetails
								{
									PreviousTaskInstanceDetails = new List<Oci.FleetappsmanagementService.Models.PreviousTaskInstanceDetails>
									{
										new Oci.FleetappsmanagementService.Models.PreviousTaskInstanceDetails
										{
											OutputVariableDetails = new Oci.FleetappsmanagementService.Models.OutputVariableDetails
											{
												StepName = "EXAMPLE-stepName-Value",
												OutputVariableName = "EXAMPLE-outputVariableName-Value"
											},
											ResourceId = "ocid1.test.oc1..<unique_ID>EXAMPLE-resourceId-Value",
											ResourceType = "EXAMPLE-resourceType-Value"
										}
									}
								},
								PreCondition = "EXAMPLE-preCondition-Value",
								ActionOnFailure = Oci.FleetappsmanagementService.Models.ComponentProperties.ActionOnFailureEnum.Continue,
								PauseDetails = new Oci.FleetappsmanagementService.Models.TimeBasedPauseDetails
								{
									DurationInMinutes = 972
								},
								NotificationPreferences = new Oci.FleetappsmanagementService.Models.TaskNotificationPreferences
								{
									ShouldNotifyOnPause = true,
									ShouldNotifyOnTaskFailure = false,
									ShouldNotifyOnTaskSuccess = false
								}
							}
						}
					},
					ExecutionWorkflowDetails = new Oci.FleetappsmanagementService.Models.ExecutionWorkflowDetails
					{
						Workflow = new List<Oci.FleetappsmanagementService.Models.WorkflowGroup>
						{
							new Oci.FleetappsmanagementService.Models.WorkflowGroup
							{
								GroupName = "EXAMPLE-groupName-Value",
								Type = Oci.FleetappsmanagementService.Models.WorkflowGroup.TypeEnum.ParallelResourceGroup,
								Steps = new List<Oci.FleetappsmanagementService.Models.WorkflowComponent>
								{
									new Oci.FleetappsmanagementService.Models.WorkflowTaskComponent
									{
										StepName = "EXAMPLE-stepName-Value"
									}
								}
							}
						}
					},
					RollbackWorkflowDetails = new Oci.FleetappsmanagementService.Models.RollbackWorkflowDetails
					{
						Scope = Oci.FleetappsmanagementService.Models.RollbackWorkflowDetails.ScopeEnum.Target,
						Workflow = new List<Oci.FleetappsmanagementService.Models.WorkflowGroup>
						{
							new Oci.FleetappsmanagementService.Models.WorkflowGroup
							{
								GroupName = "EXAMPLE-groupName-Value",
								Type = Oci.FleetappsmanagementService.Models.WorkflowGroup.TypeEnum.RollingResourceGroup,
								Steps = new List<Oci.FleetappsmanagementService.Models.WorkflowComponent>
								{
									new Oci.FleetappsmanagementService.Models.WorkflowGroupComponent
									{
										GroupName = "EXAMPLE-groupName-Value",
										Steps = new List<string>
										{
											"EXAMPLE--Value"
										}
									}
								}
							}
						}
					},
					VersionProp = "EXAMPLE-version-Value",
					IsLatest = false
				},
				CompartmentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
				FreeformTags = new Dictionary<string, string>()
				{
					{
						"EXAMPLE_KEY_NpFV8", 
						"EXAMPLE_VALUE_9v2raXA0OvenLuYKCmsT"
					}
				},
				DefinedTags = new Dictionary<string, Dictionary<string, Object>>()
				{
					{
						"EXAMPLE_KEY_XZ5IF", 
						new Dictionary<string, Object>()
						{
							{
								"EXAMPLE_KEY_yzNXB", 
								"EXAMPLE--Value"
							}
						}
					}
				}
			};
			var createRunbookRequest = new Oci.FleetappsmanagementService.Requests.CreateRunbookRequest
			{
				CreateRunbookDetails = createRunbookDetails,
				OpcRetryToken = "EXAMPLE-opcRetryToken-Value",
				OpcRequestId = "KJPS6XQ556PNLZ4JGATR<unique_ID>"
			};

            // Create a default authentication provider that uses the DEFAULT
            // profile in the configuration file.
            // Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file. 
            var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
            try
            {
                // Create a service client and send the request.
				using (var client = new FleetAppsManagementRunbooksClient(provider, new ClientConfiguration()))
				{
					var response = await client.CreateRunbook(createRunbookRequest);
					// Retrieve value from the response.
					var id = response.Runbook.Id;
				}
            }
            catch (Exception e)
            {
                Console.WriteLine($"CreateRunbook Failed with {e.Message}");
                throw e;
            }
        }

    }
}