diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index c627188..1340402 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 5a857039-7f4b-42d5-86fd-449767242ed2 management: - docChecksum: 8a2ff4be25db818a35891d602baa4a25 + docChecksum: 49e71e8528a2034de903094a70555fe5 docVersion: 1.0.0 speakeasyVersion: 1.303.4 generationVersion: 2.340.2 - releaseVersion: 0.8.2 - configChecksum: 7ce13d26abba12900e05100bdca957a2 + releaseVersion: 0.8.3 + configChecksum: e7d1645bf627310ec7c8eeead96e97ea repoURL: https://github.com/epilot-dev/terraform-provider-epilot-workflow.git repoSubDirectory: . published: true @@ -27,7 +27,6 @@ features: globalServerURLs: 2.82.1 unions: 2.81.14 generatedFiles: - - internal/sdk/closingreason.go - internal/sdk/workflows.go - internal/sdk/sdk.go - internal/sdk/models/errors/sdkerror.go @@ -46,9 +45,6 @@ generatedFiles: - internal/sdk/internal/utils/retries.go - internal/sdk/internal/utils/security.go - internal/sdk/internal/utils/utils.go - - internal/sdk/models/operations/changereasonstatus.go - - internal/sdk/models/operations/createclosingreason.go - - internal/sdk/models/operations/getallclosingreasons.go - internal/sdk/models/operations/createdefinition.go - internal/sdk/models/operations/deletedefinition.go - internal/sdk/models/operations/getdefinition.go @@ -57,11 +53,6 @@ generatedFiles: - internal/sdk/models/operations/getworkflowclosingreasons.go - internal/sdk/models/operations/setworkflowclosingreasons.go - internal/sdk/models/operations/updatedefinition.go - - internal/sdk/models/shared/errorresp.go - - internal/sdk/models/shared/changereasonstatusreq.go - - internal/sdk/models/shared/closingreasonsstatus.go - - internal/sdk/models/shared/closingreason.go - - internal/sdk/models/shared/closingreasons.go - internal/sdk/models/shared/workflowdefinition.go - internal/sdk/models/shared/updateentityattributes.go - internal/sdk/models/shared/section.go @@ -74,6 +65,7 @@ generatedFiles: - internal/sdk/models/shared/dynamicduedate.go - internal/sdk/models/shared/stepdescription.go - internal/sdk/models/shared/closingreasonid.go + - internal/sdk/models/shared/errorresp.go - internal/sdk/models/shared/definitionnotfoundresp.go - internal/sdk/models/shared/maxallowedlimit.go - internal/sdk/models/shared/closingreasonsids.go @@ -126,7 +118,26 @@ generatedFiles: - main.go - terraform-registry-manifest.json - tools/tools.go + - internal/provider/types/closing_reason_id.go + - internal/provider/types/dynamic_due_date.go + - internal/provider/types/automation_config.go + - internal/provider/types/step_description.go + - internal/provider/types/step_journey.go + - internal/provider/types/ecp_details.go + - internal/provider/types/step_requirement.go + - internal/provider/types/step.go + - internal/provider/types/section.go + - internal/provider/types/flow.go + - internal/provider/types/target.go + - internal/provider/types/update_entity_attributes.go - USAGE.md - internal/provider/provider.go - examples/provider/provider.tf + - examples/resources/epilot-workflow_workflow_definition/import.sh + - internal/provider/workflowdefinition_resource.go + - internal/provider/workflowdefinition_resource_sdk.go + - examples/resources/epilot-workflow_workflow_definition/resource.tf + - internal/provider/workflowdefinition_data_source.go + - internal/provider/workflowdefinition_data_source_sdk.go + - examples/data-sources/epilot-workflow_workflow_definition/data-source.tf - .gitattributes diff --git a/README.md b/README.md index 1049a92..250ddb1 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,54 @@ TF_REATTACH_PROVIDERS=... terraform apply + +## SDK Installation + +To install this provider, copy and paste this code into your Terraform configuration. Then, run `terraform init`. + +```hcl +terraform { + required_providers { + epilot-workflow = { + source = "epilot-dev/epilot-workflow" + version = "0.8.3" + } + } +} + +provider "epilot-workflow" { + # Configuration options +} +``` + + + +## SDK Example Usage + +### Testing the provider locally + +Should you want to validate a change locally, the `--debug` flag allows you to execute the provider against a terraform instance locally. + +This also allows for debuggers (e.g. delve) to be attached to the provider. + +### Example + +```sh +go run main.go --debug +# Copy the TF_REATTACH_PROVIDERS env var +# In a new terminal +cd examples/your-example +TF_REATTACH_PROVIDERS=... terraform init +TF_REATTACH_PROVIDERS=... terraform apply +``` + + + +## Available Resources and Operations + + + + Terraform allows you to use local provider builds by setting a `dev_overrides` block in a configuration file called `.terraformrc`. This block overrides all other configured installation methods. diff --git a/examples/data-sources/epilot-workflow_workflow_definition/data-source.tf b/examples/data-sources/epilot-workflow_workflow_definition/data-source.tf new file mode 100644 index 0000000..5159002 --- /dev/null +++ b/examples/data-sources/epilot-workflow_workflow_definition/data-source.tf @@ -0,0 +1,3 @@ +data "epilot-workflow_workflow_definition" "my_workflowdefinition" { + id = "7hj28a" +} \ No newline at end of file diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index eecd43c..76725db 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { epilot-workflow = { source = "epilot-dev/epilot-workflow" - version = "0.8.2" + version = "0.8.3" } } } diff --git a/examples/resources/epilot-workflow_workflow_definition/import.sh b/examples/resources/epilot-workflow_workflow_definition/import.sh new file mode 100644 index 0000000..4f2d498 --- /dev/null +++ b/examples/resources/epilot-workflow_workflow_definition/import.sh @@ -0,0 +1 @@ +terraform import epilot-workflow_workflow_definition.my_epilot-workflow_workflow_definition "7hj28a" diff --git a/examples/resources/epilot-workflow_workflow_definition/resource.tf b/examples/resources/epilot-workflow_workflow_definition/resource.tf index 3405316..5f4c385 100644 --- a/examples/resources/epilot-workflow_workflow_definition/resource.tf +++ b/examples/resources/epilot-workflow_workflow_definition/resource.tf @@ -1,22 +1,80 @@ -terraform { - required_providers { - epilot-workflow = { - source = "epilot-dev/epilot-workflow" - version = "1.0.1" - } - - } -} - -provider "epilot-workflow" { - # Configuration options - bearer_auth = var.bearer_auth -} - -variable "bearer_auth" { - type = string -} - resource "epilot-workflow_workflow_definition" "my_workflowdefinition" { - + creation_time = "2021-04-27T12:01:13.000Z" + description = "...my_description..." + due_date = "2021-04-27T12:00:00.000Z" + enable_ecp_workflow = false + flow = [ + { + section = { + id = "2a31ed4e-b201-4187-9740-15a348b64814" + name = "Meredith Bruen" + order = 1.95 + steps = [ + { + assigned_to = [ + "...", + ] + automation_config = { + flow_id = "...my_flow_id..." + } + description = { + enabled = true + value = "...my_value..." + } + due_date = "2021-04-27T12:00:00.000Z" + dynamic_due_date = { + action_type_condition = "STEP_CLOSED" + number_of_units = 73.8 + step_id = "...my_step_id..." + time_period = "weeks" + } + ecp = { + description = "...my_description..." + enabled = false + journey = { + id = "64361b27-76d7-498c-b5f3-e120ea0dc9e1" + journey_id = "...my_journey_id..." + name = "Lorraine Witting" + } + label = "...my_label..." + } + execution_type = "AUTOMATION" + id = "3f96aa0e-3408-45f7-9b11-76521d792fea" + installer = { + description = "...my_description..." + enabled = true + journey = { + id = "830af35a-c0f0-4516-986c-6d56674fb26d" + journey_id = "...my_journey_id..." + name = "Paulette O'Hara" + } + label = "...my_label..." + } + journey = { + id = "9b2b84e8-8293-4d18-a93f-16fc9936c940" + journey_id = "...my_journey_id..." + name = "Dr. Joel Hermann" + } + name = "Lorene Denesik" + order = 4.83 + requirements = [ + { + condition = "CLOSED" + definition_id = "...my_definition_id..." + type = "STEP" + }, + ] + type = "SECTION" + user_ids = [ + 9.27, + ] + }, + ] + type = "STEP" + } + }, + ] + id = "70408a19-3e72-4165-b76b-6381b5dd263e" + last_update_time = "2021-04-27T12:01:13.000Z" + name = "Nina Bednar" } \ No newline at end of file diff --git a/gen.yaml b/gen.yaml index d940d13..e7da5b6 100644 --- a/gen.yaml +++ b/gen.yaml @@ -27,7 +27,7 @@ go: outputModelSuffix: output packageName: openapi terraform: - version: 0.8.2 + version: 0.8.3 additionalDataSources: [] additionalDependencies: {} additionalResources: [] diff --git a/go.mod b/go.mod index 849d20f..8004ae1 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/epilot-dev/terraform-provider-epilot-workflow go 1.21 -toolchain go1.21.9 +toolchain go1.21.6 require ( github.com/cenkalti/backoff/v4 v4.2.0 diff --git a/internal/provider/provider.go b/internal/provider/provider.go index f25917a..c85b4b5 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -84,11 +84,15 @@ func (p *EpilotWorkflowProvider) Configure(ctx context.Context, req provider.Con } func (p *EpilotWorkflowProvider) Resources(ctx context.Context) []func() resource.Resource { - return []func() resource.Resource{} + return []func() resource.Resource{ + NewWorkflowDefinitionResource, + } } func (p *EpilotWorkflowProvider) DataSources(ctx context.Context) []func() datasource.DataSource { - return []func() datasource.DataSource{} + return []func() datasource.DataSource{ + NewWorkflowDefinitionDataSource, + } } func New(version string) func() provider.Provider { diff --git a/internal/provider/types/automation_config.go b/internal/provider/types/automation_config.go new file mode 100644 index 0000000..a1d19d5 --- /dev/null +++ b/internal/provider/types/automation_config.go @@ -0,0 +1,9 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type AutomationConfig struct { + FlowID types.String `tfsdk:"flow_id"` +} diff --git a/internal/provider/types/closing_reason_id.go b/internal/provider/types/closing_reason_id.go new file mode 100644 index 0000000..652a232 --- /dev/null +++ b/internal/provider/types/closing_reason_id.go @@ -0,0 +1,9 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type ClosingReasonID struct { + ID types.String `tfsdk:"id"` +} diff --git a/internal/provider/types/dynamic_due_date.go b/internal/provider/types/dynamic_due_date.go new file mode 100644 index 0000000..686bd69 --- /dev/null +++ b/internal/provider/types/dynamic_due_date.go @@ -0,0 +1,12 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type DynamicDueDate struct { + ActionTypeCondition types.String `tfsdk:"action_type_condition"` + NumberOfUnits types.Number `tfsdk:"number_of_units"` + StepID types.String `tfsdk:"step_id"` + TimePeriod types.String `tfsdk:"time_period"` +} diff --git a/internal/provider/types/ecp_details.go b/internal/provider/types/ecp_details.go new file mode 100644 index 0000000..5363e25 --- /dev/null +++ b/internal/provider/types/ecp_details.go @@ -0,0 +1,12 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type ECPDetails struct { + Description types.String `tfsdk:"description"` + Enabled types.Bool `tfsdk:"enabled"` + Journey *StepJourney `tfsdk:"journey"` + Label types.String `tfsdk:"label"` +} diff --git a/internal/provider/types/flow.go b/internal/provider/types/flow.go new file mode 100644 index 0000000..caf506b --- /dev/null +++ b/internal/provider/types/flow.go @@ -0,0 +1,8 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +type Flow struct { + Section *Section `tfsdk:"section" tfPlanOnly:"true"` + Step *Step `tfsdk:"step" tfPlanOnly:"true"` +} diff --git a/internal/provider/types/section.go b/internal/provider/types/section.go new file mode 100644 index 0000000..9b815b9 --- /dev/null +++ b/internal/provider/types/section.go @@ -0,0 +1,13 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type Section struct { + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Order types.Number `tfsdk:"order"` + Steps []Step `tfsdk:"steps"` + Type types.String `tfsdk:"type"` +} diff --git a/internal/provider/types/step.go b/internal/provider/types/step.go new file mode 100644 index 0000000..ce86cec --- /dev/null +++ b/internal/provider/types/step.go @@ -0,0 +1,23 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type Step struct { + AssignedTo []types.String `tfsdk:"assigned_to"` + AutomationConfig *AutomationConfig `tfsdk:"automation_config"` + Description *StepDescription `tfsdk:"description"` + DueDate types.String `tfsdk:"due_date"` + DynamicDueDate *DynamicDueDate `tfsdk:"dynamic_due_date"` + Ecp *ECPDetails `tfsdk:"ecp"` + ExecutionType types.String `tfsdk:"execution_type"` + ID types.String `tfsdk:"id"` + Installer *ECPDetails `tfsdk:"installer"` + Journey *StepJourney `tfsdk:"journey"` + Name types.String `tfsdk:"name"` + Order types.Number `tfsdk:"order"` + Requirements []StepRequirement `tfsdk:"requirements"` + Type types.String `tfsdk:"type"` + UserIds []types.Number `tfsdk:"user_ids"` +} diff --git a/internal/provider/types/step_description.go b/internal/provider/types/step_description.go new file mode 100644 index 0000000..b394d45 --- /dev/null +++ b/internal/provider/types/step_description.go @@ -0,0 +1,10 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type StepDescription struct { + Enabled types.Bool `tfsdk:"enabled"` + Value types.String `tfsdk:"value"` +} diff --git a/internal/provider/types/step_journey.go b/internal/provider/types/step_journey.go new file mode 100644 index 0000000..634a218 --- /dev/null +++ b/internal/provider/types/step_journey.go @@ -0,0 +1,11 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type StepJourney struct { + ID types.String `tfsdk:"id"` + JourneyID types.String `tfsdk:"journey_id"` + Name types.String `tfsdk:"name"` +} diff --git a/internal/provider/types/step_requirement.go b/internal/provider/types/step_requirement.go new file mode 100644 index 0000000..6a2366c --- /dev/null +++ b/internal/provider/types/step_requirement.go @@ -0,0 +1,11 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type StepRequirement struct { + Condition types.String `tfsdk:"condition"` + DefinitionID types.String `tfsdk:"definition_id"` + Type types.String `tfsdk:"type"` +} diff --git a/internal/provider/types/target.go b/internal/provider/types/target.go new file mode 100644 index 0000000..7529a3b --- /dev/null +++ b/internal/provider/types/target.go @@ -0,0 +1,10 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type Target struct { + EntityAttribute types.String `tfsdk:"entity_attribute"` + EntitySchema types.String `tfsdk:"entity_schema"` +} diff --git a/internal/provider/types/update_entity_attributes.go b/internal/provider/types/update_entity_attributes.go new file mode 100644 index 0000000..0a8aa9e --- /dev/null +++ b/internal/provider/types/update_entity_attributes.go @@ -0,0 +1,10 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type UpdateEntityAttributes struct { + Source types.String `tfsdk:"source"` + Target Target `tfsdk:"target"` +} diff --git a/internal/provider/workflowdefinition_data_source_sdk.go b/internal/provider/workflowdefinition_data_source_sdk.go new file mode 100644 index 0000000..0d8cdf2 --- /dev/null +++ b/internal/provider/workflowdefinition_data_source_sdk.go @@ -0,0 +1,302 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import ( + tfTypes "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/provider/types" + "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/models/shared" + "github.com/hashicorp/terraform-plugin-framework/types" + "math/big" +) + +func (r *WorkflowDefinitionDataSourceModel) RefreshFromSharedWorkflowDefinition(resp *shared.WorkflowDefinition) { + if resp != nil { + r.AssignedTo = []types.String{} + for _, v := range resp.AssignedTo { + r.AssignedTo = append(r.AssignedTo, types.StringValue(v)) + } + r.ClosingReasons = []tfTypes.ClosingReasonID{} + if len(r.ClosingReasons) > len(resp.ClosingReasons) { + r.ClosingReasons = r.ClosingReasons[:len(resp.ClosingReasons)] + } + for closingReasonsCount, closingReasonsItem := range resp.ClosingReasons { + var closingReasons1 tfTypes.ClosingReasonID + closingReasons1.ID = types.StringValue(closingReasonsItem.ID) + if closingReasonsCount+1 > len(r.ClosingReasons) { + r.ClosingReasons = append(r.ClosingReasons, closingReasons1) + } else { + r.ClosingReasons[closingReasonsCount].ID = closingReasons1.ID + } + } + r.CreationTime = types.StringPointerValue(resp.CreationTime) + r.Description = types.StringPointerValue(resp.Description) + r.DueDate = types.StringPointerValue(resp.DueDate) + if resp.DynamicDueDate == nil { + r.DynamicDueDate = nil + } else { + r.DynamicDueDate = &tfTypes.DynamicDueDate{} + r.DynamicDueDate.ActionTypeCondition = types.StringValue(string(resp.DynamicDueDate.ActionTypeCondition)) + r.DynamicDueDate.NumberOfUnits = types.NumberValue(big.NewFloat(float64(resp.DynamicDueDate.NumberOfUnits))) + r.DynamicDueDate.StepID = types.StringPointerValue(resp.DynamicDueDate.StepID) + r.DynamicDueDate.TimePeriod = types.StringValue(string(resp.DynamicDueDate.TimePeriod)) + } + r.EnableECPWorkflow = types.BoolPointerValue(resp.EnableECPWorkflow) + r.Flow = []tfTypes.Flow{} + if len(r.Flow) > len(resp.Flow) { + r.Flow = r.Flow[:len(resp.Flow)] + } + for flowCount, flowItem := range resp.Flow { + var flow1 tfTypes.Flow + if flowItem.Section != nil { + flow1.Section = &tfTypes.Section{} + flow1.Section.ID = types.StringPointerValue(flowItem.Section.ID) + flow1.Section.Name = types.StringValue(flowItem.Section.Name) + flow1.Section.Order = types.NumberValue(big.NewFloat(float64(flowItem.Section.Order))) + flow1.Section.Steps = []tfTypes.Step{} + for stepsCount, stepsItem := range flowItem.Section.Steps { + var steps1 tfTypes.Step + steps1.AssignedTo = []types.String{} + for _, v := range stepsItem.AssignedTo { + steps1.AssignedTo = append(steps1.AssignedTo, types.StringValue(v)) + } + if stepsItem.AutomationConfig == nil { + steps1.AutomationConfig = nil + } else { + steps1.AutomationConfig = &tfTypes.AutomationConfig{} + steps1.AutomationConfig.FlowID = types.StringValue(stepsItem.AutomationConfig.FlowID) + } + if stepsItem.Description == nil { + steps1.Description = nil + } else { + steps1.Description = &tfTypes.StepDescription{} + steps1.Description.Enabled = types.BoolPointerValue(stepsItem.Description.Enabled) + steps1.Description.Value = types.StringPointerValue(stepsItem.Description.Value) + } + steps1.DueDate = types.StringPointerValue(stepsItem.DueDate) + if stepsItem.DynamicDueDate == nil { + steps1.DynamicDueDate = nil + } else { + steps1.DynamicDueDate = &tfTypes.DynamicDueDate{} + steps1.DynamicDueDate.ActionTypeCondition = types.StringValue(string(stepsItem.DynamicDueDate.ActionTypeCondition)) + steps1.DynamicDueDate.NumberOfUnits = types.NumberValue(big.NewFloat(float64(stepsItem.DynamicDueDate.NumberOfUnits))) + steps1.DynamicDueDate.StepID = types.StringPointerValue(stepsItem.DynamicDueDate.StepID) + steps1.DynamicDueDate.TimePeriod = types.StringValue(string(stepsItem.DynamicDueDate.TimePeriod)) + } + if stepsItem.Ecp == nil { + steps1.Ecp = nil + } else { + steps1.Ecp = &tfTypes.ECPDetails{} + steps1.Ecp.Description = types.StringPointerValue(stepsItem.Ecp.Description) + steps1.Ecp.Enabled = types.BoolPointerValue(stepsItem.Ecp.Enabled) + if stepsItem.Ecp.Journey == nil { + steps1.Ecp.Journey = nil + } else { + steps1.Ecp.Journey = &tfTypes.StepJourney{} + steps1.Ecp.Journey.ID = types.StringPointerValue(stepsItem.Ecp.Journey.ID) + steps1.Ecp.Journey.JourneyID = types.StringPointerValue(stepsItem.Ecp.Journey.JourneyID) + steps1.Ecp.Journey.Name = types.StringPointerValue(stepsItem.Ecp.Journey.Name) + } + steps1.Ecp.Label = types.StringPointerValue(stepsItem.Ecp.Label) + } + if stepsItem.ExecutionType != nil { + steps1.ExecutionType = types.StringValue(string(*stepsItem.ExecutionType)) + } else { + steps1.ExecutionType = types.StringNull() + } + steps1.ID = types.StringPointerValue(stepsItem.ID) + if stepsItem.Installer == nil { + steps1.Installer = nil + } else { + steps1.Installer = &tfTypes.ECPDetails{} + steps1.Installer.Description = types.StringPointerValue(stepsItem.Installer.Description) + steps1.Installer.Enabled = types.BoolPointerValue(stepsItem.Installer.Enabled) + if stepsItem.Installer.Journey == nil { + steps1.Installer.Journey = nil + } else { + steps1.Installer.Journey = &tfTypes.StepJourney{} + steps1.Installer.Journey.ID = types.StringPointerValue(stepsItem.Installer.Journey.ID) + steps1.Installer.Journey.JourneyID = types.StringPointerValue(stepsItem.Installer.Journey.JourneyID) + steps1.Installer.Journey.Name = types.StringPointerValue(stepsItem.Installer.Journey.Name) + } + steps1.Installer.Label = types.StringPointerValue(stepsItem.Installer.Label) + } + if stepsItem.Journey == nil { + steps1.Journey = nil + } else { + steps1.Journey = &tfTypes.StepJourney{} + steps1.Journey.ID = types.StringPointerValue(stepsItem.Journey.ID) + steps1.Journey.JourneyID = types.StringPointerValue(stepsItem.Journey.JourneyID) + steps1.Journey.Name = types.StringPointerValue(stepsItem.Journey.Name) + } + steps1.Name = types.StringValue(stepsItem.Name) + steps1.Order = types.NumberValue(big.NewFloat(float64(stepsItem.Order))) + steps1.Requirements = []tfTypes.StepRequirement{} + for requirementsCount, requirementsItem := range stepsItem.Requirements { + var requirements1 tfTypes.StepRequirement + requirements1.Condition = types.StringValue(string(requirementsItem.Condition)) + requirements1.DefinitionID = types.StringValue(requirementsItem.DefinitionID) + requirements1.Type = types.StringValue(string(requirementsItem.Type)) + if requirementsCount+1 > len(steps1.Requirements) { + steps1.Requirements = append(steps1.Requirements, requirements1) + } else { + steps1.Requirements[requirementsCount].Condition = requirements1.Condition + steps1.Requirements[requirementsCount].DefinitionID = requirements1.DefinitionID + steps1.Requirements[requirementsCount].Type = requirements1.Type + } + } + steps1.Type = types.StringValue(string(stepsItem.Type)) + steps1.UserIds = []types.Number{} + for _, v := range stepsItem.UserIds { + steps1.UserIds = append(steps1.UserIds, types.NumberValue(big.NewFloat(float64(v)))) + } + if stepsCount+1 > len(flow1.Section.Steps) { + flow1.Section.Steps = append(flow1.Section.Steps, steps1) + } else { + flow1.Section.Steps[stepsCount].AssignedTo = steps1.AssignedTo + flow1.Section.Steps[stepsCount].AutomationConfig = steps1.AutomationConfig + flow1.Section.Steps[stepsCount].Description = steps1.Description + flow1.Section.Steps[stepsCount].DueDate = steps1.DueDate + flow1.Section.Steps[stepsCount].DynamicDueDate = steps1.DynamicDueDate + flow1.Section.Steps[stepsCount].Ecp = steps1.Ecp + flow1.Section.Steps[stepsCount].ExecutionType = steps1.ExecutionType + flow1.Section.Steps[stepsCount].ID = steps1.ID + flow1.Section.Steps[stepsCount].Installer = steps1.Installer + flow1.Section.Steps[stepsCount].Journey = steps1.Journey + flow1.Section.Steps[stepsCount].Name = steps1.Name + flow1.Section.Steps[stepsCount].Order = steps1.Order + flow1.Section.Steps[stepsCount].Requirements = steps1.Requirements + flow1.Section.Steps[stepsCount].Type = steps1.Type + flow1.Section.Steps[stepsCount].UserIds = steps1.UserIds + } + } + flow1.Section.Type = types.StringValue(string(flowItem.Section.Type)) + } + if flowItem.Step != nil { + flow1.Step = &tfTypes.Step{} + flow1.Step.AssignedTo = []types.String{} + for _, v := range flowItem.Step.AssignedTo { + flow1.Step.AssignedTo = append(flow1.Step.AssignedTo, types.StringValue(v)) + } + if flowItem.Step.AutomationConfig == nil { + flow1.Step.AutomationConfig = nil + } else { + flow1.Step.AutomationConfig = &tfTypes.AutomationConfig{} + flow1.Step.AutomationConfig.FlowID = types.StringValue(flowItem.Step.AutomationConfig.FlowID) + } + if flowItem.Step.Description == nil { + flow1.Step.Description = nil + } else { + flow1.Step.Description = &tfTypes.StepDescription{} + flow1.Step.Description.Enabled = types.BoolPointerValue(flowItem.Step.Description.Enabled) + flow1.Step.Description.Value = types.StringPointerValue(flowItem.Step.Description.Value) + } + flow1.Step.DueDate = types.StringPointerValue(flowItem.Step.DueDate) + if flowItem.Step.DynamicDueDate == nil { + flow1.Step.DynamicDueDate = nil + } else { + flow1.Step.DynamicDueDate = &tfTypes.DynamicDueDate{} + flow1.Step.DynamicDueDate.ActionTypeCondition = types.StringValue(string(flowItem.Step.DynamicDueDate.ActionTypeCondition)) + flow1.Step.DynamicDueDate.NumberOfUnits = types.NumberValue(big.NewFloat(float64(flowItem.Step.DynamicDueDate.NumberOfUnits))) + flow1.Step.DynamicDueDate.StepID = types.StringPointerValue(flowItem.Step.DynamicDueDate.StepID) + flow1.Step.DynamicDueDate.TimePeriod = types.StringValue(string(flowItem.Step.DynamicDueDate.TimePeriod)) + } + if flowItem.Step.Ecp == nil { + flow1.Step.Ecp = nil + } else { + flow1.Step.Ecp = &tfTypes.ECPDetails{} + flow1.Step.Ecp.Description = types.StringPointerValue(flowItem.Step.Ecp.Description) + flow1.Step.Ecp.Enabled = types.BoolPointerValue(flowItem.Step.Ecp.Enabled) + if flowItem.Step.Ecp.Journey == nil { + flow1.Step.Ecp.Journey = nil + } else { + flow1.Step.Ecp.Journey = &tfTypes.StepJourney{} + flow1.Step.Ecp.Journey.ID = types.StringPointerValue(flowItem.Step.Ecp.Journey.ID) + flow1.Step.Ecp.Journey.JourneyID = types.StringPointerValue(flowItem.Step.Ecp.Journey.JourneyID) + flow1.Step.Ecp.Journey.Name = types.StringPointerValue(flowItem.Step.Ecp.Journey.Name) + } + flow1.Step.Ecp.Label = types.StringPointerValue(flowItem.Step.Ecp.Label) + } + if flowItem.Step.ExecutionType != nil { + flow1.Step.ExecutionType = types.StringValue(string(*flowItem.Step.ExecutionType)) + } else { + flow1.Step.ExecutionType = types.StringNull() + } + flow1.Step.ID = types.StringPointerValue(flowItem.Step.ID) + if flowItem.Step.Installer == nil { + flow1.Step.Installer = nil + } else { + flow1.Step.Installer = &tfTypes.ECPDetails{} + flow1.Step.Installer.Description = types.StringPointerValue(flowItem.Step.Installer.Description) + flow1.Step.Installer.Enabled = types.BoolPointerValue(flowItem.Step.Installer.Enabled) + if flowItem.Step.Installer.Journey == nil { + flow1.Step.Installer.Journey = nil + } else { + flow1.Step.Installer.Journey = &tfTypes.StepJourney{} + flow1.Step.Installer.Journey.ID = types.StringPointerValue(flowItem.Step.Installer.Journey.ID) + flow1.Step.Installer.Journey.JourneyID = types.StringPointerValue(flowItem.Step.Installer.Journey.JourneyID) + flow1.Step.Installer.Journey.Name = types.StringPointerValue(flowItem.Step.Installer.Journey.Name) + } + flow1.Step.Installer.Label = types.StringPointerValue(flowItem.Step.Installer.Label) + } + if flowItem.Step.Journey == nil { + flow1.Step.Journey = nil + } else { + flow1.Step.Journey = &tfTypes.StepJourney{} + flow1.Step.Journey.ID = types.StringPointerValue(flowItem.Step.Journey.ID) + flow1.Step.Journey.JourneyID = types.StringPointerValue(flowItem.Step.Journey.JourneyID) + flow1.Step.Journey.Name = types.StringPointerValue(flowItem.Step.Journey.Name) + } + flow1.Step.Name = types.StringValue(flowItem.Step.Name) + flow1.Step.Order = types.NumberValue(big.NewFloat(float64(flowItem.Step.Order))) + flow1.Step.Requirements = []tfTypes.StepRequirement{} + for requirementsCount1, requirementsItem1 := range flowItem.Step.Requirements { + var requirements3 tfTypes.StepRequirement + requirements3.Condition = types.StringValue(string(requirementsItem1.Condition)) + requirements3.DefinitionID = types.StringValue(requirementsItem1.DefinitionID) + requirements3.Type = types.StringValue(string(requirementsItem1.Type)) + if requirementsCount1+1 > len(flow1.Step.Requirements) { + flow1.Step.Requirements = append(flow1.Step.Requirements, requirements3) + } else { + flow1.Step.Requirements[requirementsCount1].Condition = requirements3.Condition + flow1.Step.Requirements[requirementsCount1].DefinitionID = requirements3.DefinitionID + flow1.Step.Requirements[requirementsCount1].Type = requirements3.Type + } + } + flow1.Step.Type = types.StringValue(string(flowItem.Step.Type)) + flow1.Step.UserIds = []types.Number{} + for _, v := range flowItem.Step.UserIds { + flow1.Step.UserIds = append(flow1.Step.UserIds, types.NumberValue(big.NewFloat(float64(v)))) + } + } + if flowCount+1 > len(r.Flow) { + r.Flow = append(r.Flow, flow1) + } else { + r.Flow[flowCount].Section = flow1.Section + r.Flow[flowCount].Step = flow1.Step + } + } + r.ID = types.StringPointerValue(resp.ID) + r.LastUpdateTime = types.StringPointerValue(resp.LastUpdateTime) + r.Name = types.StringValue(resp.Name) + r.UpdateEntityAttributes = []tfTypes.UpdateEntityAttributes{} + if len(r.UpdateEntityAttributes) > len(resp.UpdateEntityAttributes) { + r.UpdateEntityAttributes = r.UpdateEntityAttributes[:len(resp.UpdateEntityAttributes)] + } + for updateEntityAttributesCount, updateEntityAttributesItem := range resp.UpdateEntityAttributes { + var updateEntityAttributes1 tfTypes.UpdateEntityAttributes + updateEntityAttributes1.Source = types.StringValue(string(updateEntityAttributesItem.Source)) + updateEntityAttributes1.Target.EntityAttribute = types.StringValue(updateEntityAttributesItem.Target.EntityAttribute) + updateEntityAttributes1.Target.EntitySchema = types.StringValue(updateEntityAttributesItem.Target.EntitySchema) + if updateEntityAttributesCount+1 > len(r.UpdateEntityAttributes) { + r.UpdateEntityAttributes = append(r.UpdateEntityAttributes, updateEntityAttributes1) + } else { + r.UpdateEntityAttributes[updateEntityAttributesCount].Source = updateEntityAttributes1.Source + r.UpdateEntityAttributes[updateEntityAttributesCount].Target = updateEntityAttributes1.Target + } + } + r.UserIds = []types.Number{} + for _, v := range resp.UserIds { + r.UserIds = append(r.UserIds, types.NumberValue(big.NewFloat(float64(v)))) + } + } +} diff --git a/internal/provider/workflowdefinition_resource_sdk.go b/internal/provider/workflowdefinition_resource_sdk.go new file mode 100644 index 0000000..d12a38a --- /dev/null +++ b/internal/provider/workflowdefinition_resource_sdk.go @@ -0,0 +1,906 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import ( + tfTypes "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/provider/types" + "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/models/shared" + "github.com/hashicorp/terraform-plugin-framework/types" + "math/big" +) + +func (r *WorkflowDefinitionResourceModel) ToSharedWorkflowDefinition() *shared.WorkflowDefinition { + var assignedTo []string = []string{} + for _, assignedToItem := range r.AssignedTo { + assignedTo = append(assignedTo, assignedToItem.ValueString()) + } + var closingReasons []shared.ClosingReasonID = []shared.ClosingReasonID{} + for _, closingReasonsItem := range r.ClosingReasons { + id := closingReasonsItem.ID.ValueString() + closingReasons = append(closingReasons, shared.ClosingReasonID{ + ID: id, + }) + } + creationTime := new(string) + if !r.CreationTime.IsUnknown() && !r.CreationTime.IsNull() { + *creationTime = r.CreationTime.ValueString() + } else { + creationTime = nil + } + description := new(string) + if !r.Description.IsUnknown() && !r.Description.IsNull() { + *description = r.Description.ValueString() + } else { + description = nil + } + dueDate := new(string) + if !r.DueDate.IsUnknown() && !r.DueDate.IsNull() { + *dueDate = r.DueDate.ValueString() + } else { + dueDate = nil + } + var dynamicDueDate *shared.DynamicDueDate + if r.DynamicDueDate != nil { + actionTypeCondition := shared.ActionTypeCondition(r.DynamicDueDate.ActionTypeCondition.ValueString()) + numberOfUnits, _ := r.DynamicDueDate.NumberOfUnits.ValueBigFloat().Float64() + stepID := new(string) + if !r.DynamicDueDate.StepID.IsUnknown() && !r.DynamicDueDate.StepID.IsNull() { + *stepID = r.DynamicDueDate.StepID.ValueString() + } else { + stepID = nil + } + timePeriod := shared.TimePeriod(r.DynamicDueDate.TimePeriod.ValueString()) + dynamicDueDate = &shared.DynamicDueDate{ + ActionTypeCondition: actionTypeCondition, + NumberOfUnits: numberOfUnits, + StepID: stepID, + TimePeriod: timePeriod, + } + } + enableECPWorkflow := new(bool) + if !r.EnableECPWorkflow.IsUnknown() && !r.EnableECPWorkflow.IsNull() { + *enableECPWorkflow = r.EnableECPWorkflow.ValueBool() + } else { + enableECPWorkflow = nil + } + var flow []shared.Flow = []shared.Flow{} + for _, flowItem := range r.Flow { + if flowItem.Section != nil { + id1 := new(string) + if !flowItem.Section.ID.IsUnknown() && !flowItem.Section.ID.IsNull() { + *id1 = flowItem.Section.ID.ValueString() + } else { + id1 = nil + } + name := flowItem.Section.Name.ValueString() + order, _ := flowItem.Section.Order.ValueBigFloat().Float64() + var steps []shared.Step = []shared.Step{} + for _, stepsItem := range flowItem.Section.Steps { + var assignedTo1 []string = []string{} + for _, assignedToItem1 := range stepsItem.AssignedTo { + assignedTo1 = append(assignedTo1, assignedToItem1.ValueString()) + } + var automationConfig *shared.AutomationConfig + if stepsItem.AutomationConfig != nil { + flowID := stepsItem.AutomationConfig.FlowID.ValueString() + automationConfig = &shared.AutomationConfig{ + FlowID: flowID, + } + } + var description1 *shared.StepDescription + if stepsItem.Description != nil { + enabled := new(bool) + if !stepsItem.Description.Enabled.IsUnknown() && !stepsItem.Description.Enabled.IsNull() { + *enabled = stepsItem.Description.Enabled.ValueBool() + } else { + enabled = nil + } + value := new(string) + if !stepsItem.Description.Value.IsUnknown() && !stepsItem.Description.Value.IsNull() { + *value = stepsItem.Description.Value.ValueString() + } else { + value = nil + } + description1 = &shared.StepDescription{ + Enabled: enabled, + Value: value, + } + } + dueDate1 := new(string) + if !stepsItem.DueDate.IsUnknown() && !stepsItem.DueDate.IsNull() { + *dueDate1 = stepsItem.DueDate.ValueString() + } else { + dueDate1 = nil + } + var dynamicDueDate1 *shared.DynamicDueDate + if stepsItem.DynamicDueDate != nil { + actionTypeCondition1 := shared.ActionTypeCondition(stepsItem.DynamicDueDate.ActionTypeCondition.ValueString()) + numberOfUnits1, _ := stepsItem.DynamicDueDate.NumberOfUnits.ValueBigFloat().Float64() + stepId1 := new(string) + if !stepsItem.DynamicDueDate.StepID.IsUnknown() && !stepsItem.DynamicDueDate.StepID.IsNull() { + *stepId1 = stepsItem.DynamicDueDate.StepID.ValueString() + } else { + stepId1 = nil + } + timePeriod1 := shared.TimePeriod(stepsItem.DynamicDueDate.TimePeriod.ValueString()) + dynamicDueDate1 = &shared.DynamicDueDate{ + ActionTypeCondition: actionTypeCondition1, + NumberOfUnits: numberOfUnits1, + StepID: stepId1, + TimePeriod: timePeriod1, + } + } + var ecp *shared.ECPDetails + if stepsItem.Ecp != nil { + description2 := new(string) + if !stepsItem.Ecp.Description.IsUnknown() && !stepsItem.Ecp.Description.IsNull() { + *description2 = stepsItem.Ecp.Description.ValueString() + } else { + description2 = nil + } + enabled1 := new(bool) + if !stepsItem.Ecp.Enabled.IsUnknown() && !stepsItem.Ecp.Enabled.IsNull() { + *enabled1 = stepsItem.Ecp.Enabled.ValueBool() + } else { + enabled1 = nil + } + var journey *shared.StepJourney + if stepsItem.Ecp.Journey != nil { + id2 := new(string) + if !stepsItem.Ecp.Journey.ID.IsUnknown() && !stepsItem.Ecp.Journey.ID.IsNull() { + *id2 = stepsItem.Ecp.Journey.ID.ValueString() + } else { + id2 = nil + } + journeyID := new(string) + if !stepsItem.Ecp.Journey.JourneyID.IsUnknown() && !stepsItem.Ecp.Journey.JourneyID.IsNull() { + *journeyID = stepsItem.Ecp.Journey.JourneyID.ValueString() + } else { + journeyID = nil + } + name1 := new(string) + if !stepsItem.Ecp.Journey.Name.IsUnknown() && !stepsItem.Ecp.Journey.Name.IsNull() { + *name1 = stepsItem.Ecp.Journey.Name.ValueString() + } else { + name1 = nil + } + journey = &shared.StepJourney{ + ID: id2, + JourneyID: journeyID, + Name: name1, + } + } + label := new(string) + if !stepsItem.Ecp.Label.IsUnknown() && !stepsItem.Ecp.Label.IsNull() { + *label = stepsItem.Ecp.Label.ValueString() + } else { + label = nil + } + ecp = &shared.ECPDetails{ + Description: description2, + Enabled: enabled1, + Journey: journey, + Label: label, + } + } + executionType := new(shared.StepType) + if !stepsItem.ExecutionType.IsUnknown() && !stepsItem.ExecutionType.IsNull() { + *executionType = shared.StepType(stepsItem.ExecutionType.ValueString()) + } else { + executionType = nil + } + id3 := new(string) + if !stepsItem.ID.IsUnknown() && !stepsItem.ID.IsNull() { + *id3 = stepsItem.ID.ValueString() + } else { + id3 = nil + } + var installer *shared.ECPDetails + if stepsItem.Installer != nil { + description3 := new(string) + if !stepsItem.Installer.Description.IsUnknown() && !stepsItem.Installer.Description.IsNull() { + *description3 = stepsItem.Installer.Description.ValueString() + } else { + description3 = nil + } + enabled2 := new(bool) + if !stepsItem.Installer.Enabled.IsUnknown() && !stepsItem.Installer.Enabled.IsNull() { + *enabled2 = stepsItem.Installer.Enabled.ValueBool() + } else { + enabled2 = nil + } + var journey1 *shared.StepJourney + if stepsItem.Installer.Journey != nil { + id4 := new(string) + if !stepsItem.Installer.Journey.ID.IsUnknown() && !stepsItem.Installer.Journey.ID.IsNull() { + *id4 = stepsItem.Installer.Journey.ID.ValueString() + } else { + id4 = nil + } + journeyId1 := new(string) + if !stepsItem.Installer.Journey.JourneyID.IsUnknown() && !stepsItem.Installer.Journey.JourneyID.IsNull() { + *journeyId1 = stepsItem.Installer.Journey.JourneyID.ValueString() + } else { + journeyId1 = nil + } + name2 := new(string) + if !stepsItem.Installer.Journey.Name.IsUnknown() && !stepsItem.Installer.Journey.Name.IsNull() { + *name2 = stepsItem.Installer.Journey.Name.ValueString() + } else { + name2 = nil + } + journey1 = &shared.StepJourney{ + ID: id4, + JourneyID: journeyId1, + Name: name2, + } + } + label1 := new(string) + if !stepsItem.Installer.Label.IsUnknown() && !stepsItem.Installer.Label.IsNull() { + *label1 = stepsItem.Installer.Label.ValueString() + } else { + label1 = nil + } + installer = &shared.ECPDetails{ + Description: description3, + Enabled: enabled2, + Journey: journey1, + Label: label1, + } + } + var journey2 *shared.StepJourney + if stepsItem.Journey != nil { + id5 := new(string) + if !stepsItem.Journey.ID.IsUnknown() && !stepsItem.Journey.ID.IsNull() { + *id5 = stepsItem.Journey.ID.ValueString() + } else { + id5 = nil + } + journeyId2 := new(string) + if !stepsItem.Journey.JourneyID.IsUnknown() && !stepsItem.Journey.JourneyID.IsNull() { + *journeyId2 = stepsItem.Journey.JourneyID.ValueString() + } else { + journeyId2 = nil + } + name3 := new(string) + if !stepsItem.Journey.Name.IsUnknown() && !stepsItem.Journey.Name.IsNull() { + *name3 = stepsItem.Journey.Name.ValueString() + } else { + name3 = nil + } + journey2 = &shared.StepJourney{ + ID: id5, + JourneyID: journeyId2, + Name: name3, + } + } + name4 := stepsItem.Name.ValueString() + order1, _ := stepsItem.Order.ValueBigFloat().Float64() + var requirements []shared.StepRequirement = []shared.StepRequirement{} + for _, requirementsItem := range stepsItem.Requirements { + condition := shared.Condition(requirementsItem.Condition.ValueString()) + definitionID := requirementsItem.DefinitionID.ValueString() + typeVar := shared.ItemType(requirementsItem.Type.ValueString()) + requirements = append(requirements, shared.StepRequirement{ + Condition: condition, + DefinitionID: definitionID, + Type: typeVar, + }) + } + type1 := shared.ItemType(stepsItem.Type.ValueString()) + var userIds []float64 = []float64{} + for _, userIdsItem := range stepsItem.UserIds { + userIdsTmp, _ := userIdsItem.ValueBigFloat().Float64() + userIds = append(userIds, userIdsTmp) + } + steps = append(steps, shared.Step{ + AssignedTo: assignedTo1, + AutomationConfig: automationConfig, + Description: description1, + DueDate: dueDate1, + DynamicDueDate: dynamicDueDate1, + Ecp: ecp, + ExecutionType: executionType, + ID: id3, + Installer: installer, + Journey: journey2, + Name: name4, + Order: order1, + Requirements: requirements, + Type: type1, + UserIds: userIds, + }) + } + typeVar1 := shared.ItemType(flowItem.Section.Type.ValueString()) + section := shared.Section{ + ID: id1, + Name: name, + Order: order, + Steps: steps, + Type: typeVar1, + } + flow = append(flow, shared.Flow{ + Section: §ion, + }) + } + if flowItem.Step != nil { + var assignedTo2 []string = []string{} + for _, assignedToItem2 := range flowItem.Step.AssignedTo { + assignedTo2 = append(assignedTo2, assignedToItem2.ValueString()) + } + var automationConfig1 *shared.AutomationConfig + if flowItem.Step.AutomationConfig != nil { + flowId1 := flowItem.Step.AutomationConfig.FlowID.ValueString() + automationConfig1 = &shared.AutomationConfig{ + FlowID: flowId1, + } + } + var description4 *shared.StepDescription + if flowItem.Step.Description != nil { + enabled3 := new(bool) + if !flowItem.Step.Description.Enabled.IsUnknown() && !flowItem.Step.Description.Enabled.IsNull() { + *enabled3 = flowItem.Step.Description.Enabled.ValueBool() + } else { + enabled3 = nil + } + value1 := new(string) + if !flowItem.Step.Description.Value.IsUnknown() && !flowItem.Step.Description.Value.IsNull() { + *value1 = flowItem.Step.Description.Value.ValueString() + } else { + value1 = nil + } + description4 = &shared.StepDescription{ + Enabled: enabled3, + Value: value1, + } + } + dueDate2 := new(string) + if !flowItem.Step.DueDate.IsUnknown() && !flowItem.Step.DueDate.IsNull() { + *dueDate2 = flowItem.Step.DueDate.ValueString() + } else { + dueDate2 = nil + } + var dynamicDueDate2 *shared.DynamicDueDate + if flowItem.Step.DynamicDueDate != nil { + actionTypeCondition2 := shared.ActionTypeCondition(flowItem.Step.DynamicDueDate.ActionTypeCondition.ValueString()) + numberOfUnits2, _ := flowItem.Step.DynamicDueDate.NumberOfUnits.ValueBigFloat().Float64() + stepId2 := new(string) + if !flowItem.Step.DynamicDueDate.StepID.IsUnknown() && !flowItem.Step.DynamicDueDate.StepID.IsNull() { + *stepId2 = flowItem.Step.DynamicDueDate.StepID.ValueString() + } else { + stepId2 = nil + } + timePeriod2 := shared.TimePeriod(flowItem.Step.DynamicDueDate.TimePeriod.ValueString()) + dynamicDueDate2 = &shared.DynamicDueDate{ + ActionTypeCondition: actionTypeCondition2, + NumberOfUnits: numberOfUnits2, + StepID: stepId2, + TimePeriod: timePeriod2, + } + } + var ecp1 *shared.ECPDetails + if flowItem.Step.Ecp != nil { + description5 := new(string) + if !flowItem.Step.Ecp.Description.IsUnknown() && !flowItem.Step.Ecp.Description.IsNull() { + *description5 = flowItem.Step.Ecp.Description.ValueString() + } else { + description5 = nil + } + enabled4 := new(bool) + if !flowItem.Step.Ecp.Enabled.IsUnknown() && !flowItem.Step.Ecp.Enabled.IsNull() { + *enabled4 = flowItem.Step.Ecp.Enabled.ValueBool() + } else { + enabled4 = nil + } + var journey3 *shared.StepJourney + if flowItem.Step.Ecp.Journey != nil { + id6 := new(string) + if !flowItem.Step.Ecp.Journey.ID.IsUnknown() && !flowItem.Step.Ecp.Journey.ID.IsNull() { + *id6 = flowItem.Step.Ecp.Journey.ID.ValueString() + } else { + id6 = nil + } + journeyId3 := new(string) + if !flowItem.Step.Ecp.Journey.JourneyID.IsUnknown() && !flowItem.Step.Ecp.Journey.JourneyID.IsNull() { + *journeyId3 = flowItem.Step.Ecp.Journey.JourneyID.ValueString() + } else { + journeyId3 = nil + } + name5 := new(string) + if !flowItem.Step.Ecp.Journey.Name.IsUnknown() && !flowItem.Step.Ecp.Journey.Name.IsNull() { + *name5 = flowItem.Step.Ecp.Journey.Name.ValueString() + } else { + name5 = nil + } + journey3 = &shared.StepJourney{ + ID: id6, + JourneyID: journeyId3, + Name: name5, + } + } + label2 := new(string) + if !flowItem.Step.Ecp.Label.IsUnknown() && !flowItem.Step.Ecp.Label.IsNull() { + *label2 = flowItem.Step.Ecp.Label.ValueString() + } else { + label2 = nil + } + ecp1 = &shared.ECPDetails{ + Description: description5, + Enabled: enabled4, + Journey: journey3, + Label: label2, + } + } + executionType1 := new(shared.StepType) + if !flowItem.Step.ExecutionType.IsUnknown() && !flowItem.Step.ExecutionType.IsNull() { + *executionType1 = shared.StepType(flowItem.Step.ExecutionType.ValueString()) + } else { + executionType1 = nil + } + id7 := new(string) + if !flowItem.Step.ID.IsUnknown() && !flowItem.Step.ID.IsNull() { + *id7 = flowItem.Step.ID.ValueString() + } else { + id7 = nil + } + var installer1 *shared.ECPDetails + if flowItem.Step.Installer != nil { + description6 := new(string) + if !flowItem.Step.Installer.Description.IsUnknown() && !flowItem.Step.Installer.Description.IsNull() { + *description6 = flowItem.Step.Installer.Description.ValueString() + } else { + description6 = nil + } + enabled5 := new(bool) + if !flowItem.Step.Installer.Enabled.IsUnknown() && !flowItem.Step.Installer.Enabled.IsNull() { + *enabled5 = flowItem.Step.Installer.Enabled.ValueBool() + } else { + enabled5 = nil + } + var journey4 *shared.StepJourney + if flowItem.Step.Installer.Journey != nil { + id8 := new(string) + if !flowItem.Step.Installer.Journey.ID.IsUnknown() && !flowItem.Step.Installer.Journey.ID.IsNull() { + *id8 = flowItem.Step.Installer.Journey.ID.ValueString() + } else { + id8 = nil + } + journeyId4 := new(string) + if !flowItem.Step.Installer.Journey.JourneyID.IsUnknown() && !flowItem.Step.Installer.Journey.JourneyID.IsNull() { + *journeyId4 = flowItem.Step.Installer.Journey.JourneyID.ValueString() + } else { + journeyId4 = nil + } + name6 := new(string) + if !flowItem.Step.Installer.Journey.Name.IsUnknown() && !flowItem.Step.Installer.Journey.Name.IsNull() { + *name6 = flowItem.Step.Installer.Journey.Name.ValueString() + } else { + name6 = nil + } + journey4 = &shared.StepJourney{ + ID: id8, + JourneyID: journeyId4, + Name: name6, + } + } + label3 := new(string) + if !flowItem.Step.Installer.Label.IsUnknown() && !flowItem.Step.Installer.Label.IsNull() { + *label3 = flowItem.Step.Installer.Label.ValueString() + } else { + label3 = nil + } + installer1 = &shared.ECPDetails{ + Description: description6, + Enabled: enabled5, + Journey: journey4, + Label: label3, + } + } + var journey5 *shared.StepJourney + if flowItem.Step.Journey != nil { + id9 := new(string) + if !flowItem.Step.Journey.ID.IsUnknown() && !flowItem.Step.Journey.ID.IsNull() { + *id9 = flowItem.Step.Journey.ID.ValueString() + } else { + id9 = nil + } + journeyId5 := new(string) + if !flowItem.Step.Journey.JourneyID.IsUnknown() && !flowItem.Step.Journey.JourneyID.IsNull() { + *journeyId5 = flowItem.Step.Journey.JourneyID.ValueString() + } else { + journeyId5 = nil + } + name7 := new(string) + if !flowItem.Step.Journey.Name.IsUnknown() && !flowItem.Step.Journey.Name.IsNull() { + *name7 = flowItem.Step.Journey.Name.ValueString() + } else { + name7 = nil + } + journey5 = &shared.StepJourney{ + ID: id9, + JourneyID: journeyId5, + Name: name7, + } + } + name8 := flowItem.Step.Name.ValueString() + order2, _ := flowItem.Step.Order.ValueBigFloat().Float64() + var requirements1 []shared.StepRequirement = []shared.StepRequirement{} + for _, requirementsItem1 := range flowItem.Step.Requirements { + condition1 := shared.Condition(requirementsItem1.Condition.ValueString()) + definitionId1 := requirementsItem1.DefinitionID.ValueString() + type2 := shared.ItemType(requirementsItem1.Type.ValueString()) + requirements1 = append(requirements1, shared.StepRequirement{ + Condition: condition1, + DefinitionID: definitionId1, + Type: type2, + }) + } + typeVar2 := shared.ItemType(flowItem.Step.Type.ValueString()) + var userIds1 []float64 = []float64{} + for _, userIdsItem1 := range flowItem.Step.UserIds { + userIdsTmp1, _ := userIdsItem1.ValueBigFloat().Float64() + userIds1 = append(userIds1, userIdsTmp1) + } + step := shared.Step{ + AssignedTo: assignedTo2, + AutomationConfig: automationConfig1, + Description: description4, + DueDate: dueDate2, + DynamicDueDate: dynamicDueDate2, + Ecp: ecp1, + ExecutionType: executionType1, + ID: id7, + Installer: installer1, + Journey: journey5, + Name: name8, + Order: order2, + Requirements: requirements1, + Type: typeVar2, + UserIds: userIds1, + } + flow = append(flow, shared.Flow{ + Step: &step, + }) + } + } + id10 := new(string) + if !r.ID.IsUnknown() && !r.ID.IsNull() { + *id10 = r.ID.ValueString() + } else { + id10 = nil + } + lastUpdateTime := new(string) + if !r.LastUpdateTime.IsUnknown() && !r.LastUpdateTime.IsNull() { + *lastUpdateTime = r.LastUpdateTime.ValueString() + } else { + lastUpdateTime = nil + } + name9 := r.Name.ValueString() + var updateEntityAttributes []shared.UpdateEntityAttributes = []shared.UpdateEntityAttributes{} + for _, updateEntityAttributesItem := range r.UpdateEntityAttributes { + source := shared.Source(updateEntityAttributesItem.Source.ValueString()) + entityAttribute := updateEntityAttributesItem.Target.EntityAttribute.ValueString() + entitySchema := updateEntityAttributesItem.Target.EntitySchema.ValueString() + target := shared.Target{ + EntityAttribute: entityAttribute, + EntitySchema: entitySchema, + } + updateEntityAttributes = append(updateEntityAttributes, shared.UpdateEntityAttributes{ + Source: source, + Target: target, + }) + } + var userIds2 []float64 = []float64{} + for _, userIdsItem2 := range r.UserIds { + userIdsTmp2, _ := userIdsItem2.ValueBigFloat().Float64() + userIds2 = append(userIds2, userIdsTmp2) + } + out := shared.WorkflowDefinition{ + AssignedTo: assignedTo, + ClosingReasons: closingReasons, + CreationTime: creationTime, + Description: description, + DueDate: dueDate, + DynamicDueDate: dynamicDueDate, + EnableECPWorkflow: enableECPWorkflow, + Flow: flow, + ID: id10, + LastUpdateTime: lastUpdateTime, + Name: name9, + UpdateEntityAttributes: updateEntityAttributes, + UserIds: userIds2, + } + return &out +} + +func (r *WorkflowDefinitionResourceModel) RefreshFromSharedWorkflowDefinition(resp *shared.WorkflowDefinition) { + if resp != nil { + r.AssignedTo = []types.String{} + for _, v := range resp.AssignedTo { + r.AssignedTo = append(r.AssignedTo, types.StringValue(v)) + } + r.ClosingReasons = []tfTypes.ClosingReasonID{} + if len(r.ClosingReasons) > len(resp.ClosingReasons) { + r.ClosingReasons = r.ClosingReasons[:len(resp.ClosingReasons)] + } + for closingReasonsCount, closingReasonsItem := range resp.ClosingReasons { + var closingReasons1 tfTypes.ClosingReasonID + closingReasons1.ID = types.StringValue(closingReasonsItem.ID) + if closingReasonsCount+1 > len(r.ClosingReasons) { + r.ClosingReasons = append(r.ClosingReasons, closingReasons1) + } else { + r.ClosingReasons[closingReasonsCount].ID = closingReasons1.ID + } + } + r.CreationTime = types.StringPointerValue(resp.CreationTime) + r.Description = types.StringPointerValue(resp.Description) + r.DueDate = types.StringPointerValue(resp.DueDate) + if resp.DynamicDueDate == nil { + r.DynamicDueDate = nil + } else { + r.DynamicDueDate = &tfTypes.DynamicDueDate{} + r.DynamicDueDate.ActionTypeCondition = types.StringValue(string(resp.DynamicDueDate.ActionTypeCondition)) + r.DynamicDueDate.NumberOfUnits = types.NumberValue(big.NewFloat(float64(resp.DynamicDueDate.NumberOfUnits))) + r.DynamicDueDate.StepID = types.StringPointerValue(resp.DynamicDueDate.StepID) + r.DynamicDueDate.TimePeriod = types.StringValue(string(resp.DynamicDueDate.TimePeriod)) + } + r.EnableECPWorkflow = types.BoolPointerValue(resp.EnableECPWorkflow) + r.Flow = []tfTypes.Flow{} + if len(r.Flow) > len(resp.Flow) { + r.Flow = r.Flow[:len(resp.Flow)] + } + for flowCount, flowItem := range resp.Flow { + var flow1 tfTypes.Flow + if flowItem.Section != nil { + flow1.Section = &tfTypes.Section{} + flow1.Section.ID = types.StringPointerValue(flowItem.Section.ID) + flow1.Section.Name = types.StringValue(flowItem.Section.Name) + flow1.Section.Order = types.NumberValue(big.NewFloat(float64(flowItem.Section.Order))) + flow1.Section.Steps = []tfTypes.Step{} + for stepsCount, stepsItem := range flowItem.Section.Steps { + var steps1 tfTypes.Step + steps1.AssignedTo = []types.String{} + for _, v := range stepsItem.AssignedTo { + steps1.AssignedTo = append(steps1.AssignedTo, types.StringValue(v)) + } + if stepsItem.AutomationConfig == nil { + steps1.AutomationConfig = nil + } else { + steps1.AutomationConfig = &tfTypes.AutomationConfig{} + steps1.AutomationConfig.FlowID = types.StringValue(stepsItem.AutomationConfig.FlowID) + } + if stepsItem.Description == nil { + steps1.Description = nil + } else { + steps1.Description = &tfTypes.StepDescription{} + steps1.Description.Enabled = types.BoolPointerValue(stepsItem.Description.Enabled) + steps1.Description.Value = types.StringPointerValue(stepsItem.Description.Value) + } + steps1.DueDate = types.StringPointerValue(stepsItem.DueDate) + if stepsItem.DynamicDueDate == nil { + steps1.DynamicDueDate = nil + } else { + steps1.DynamicDueDate = &tfTypes.DynamicDueDate{} + steps1.DynamicDueDate.ActionTypeCondition = types.StringValue(string(stepsItem.DynamicDueDate.ActionTypeCondition)) + steps1.DynamicDueDate.NumberOfUnits = types.NumberValue(big.NewFloat(float64(stepsItem.DynamicDueDate.NumberOfUnits))) + steps1.DynamicDueDate.StepID = types.StringPointerValue(stepsItem.DynamicDueDate.StepID) + steps1.DynamicDueDate.TimePeriod = types.StringValue(string(stepsItem.DynamicDueDate.TimePeriod)) + } + if stepsItem.Ecp == nil { + steps1.Ecp = nil + } else { + steps1.Ecp = &tfTypes.ECPDetails{} + steps1.Ecp.Description = types.StringPointerValue(stepsItem.Ecp.Description) + steps1.Ecp.Enabled = types.BoolPointerValue(stepsItem.Ecp.Enabled) + if stepsItem.Ecp.Journey == nil { + steps1.Ecp.Journey = nil + } else { + steps1.Ecp.Journey = &tfTypes.StepJourney{} + steps1.Ecp.Journey.ID = types.StringPointerValue(stepsItem.Ecp.Journey.ID) + steps1.Ecp.Journey.JourneyID = types.StringPointerValue(stepsItem.Ecp.Journey.JourneyID) + steps1.Ecp.Journey.Name = types.StringPointerValue(stepsItem.Ecp.Journey.Name) + } + steps1.Ecp.Label = types.StringPointerValue(stepsItem.Ecp.Label) + } + if stepsItem.ExecutionType != nil { + steps1.ExecutionType = types.StringValue(string(*stepsItem.ExecutionType)) + } else { + steps1.ExecutionType = types.StringNull() + } + steps1.ID = types.StringPointerValue(stepsItem.ID) + if stepsItem.Installer == nil { + steps1.Installer = nil + } else { + steps1.Installer = &tfTypes.ECPDetails{} + steps1.Installer.Description = types.StringPointerValue(stepsItem.Installer.Description) + steps1.Installer.Enabled = types.BoolPointerValue(stepsItem.Installer.Enabled) + if stepsItem.Installer.Journey == nil { + steps1.Installer.Journey = nil + } else { + steps1.Installer.Journey = &tfTypes.StepJourney{} + steps1.Installer.Journey.ID = types.StringPointerValue(stepsItem.Installer.Journey.ID) + steps1.Installer.Journey.JourneyID = types.StringPointerValue(stepsItem.Installer.Journey.JourneyID) + steps1.Installer.Journey.Name = types.StringPointerValue(stepsItem.Installer.Journey.Name) + } + steps1.Installer.Label = types.StringPointerValue(stepsItem.Installer.Label) + } + if stepsItem.Journey == nil { + steps1.Journey = nil + } else { + steps1.Journey = &tfTypes.StepJourney{} + steps1.Journey.ID = types.StringPointerValue(stepsItem.Journey.ID) + steps1.Journey.JourneyID = types.StringPointerValue(stepsItem.Journey.JourneyID) + steps1.Journey.Name = types.StringPointerValue(stepsItem.Journey.Name) + } + steps1.Name = types.StringValue(stepsItem.Name) + steps1.Order = types.NumberValue(big.NewFloat(float64(stepsItem.Order))) + steps1.Requirements = []tfTypes.StepRequirement{} + for requirementsCount, requirementsItem := range stepsItem.Requirements { + var requirements1 tfTypes.StepRequirement + requirements1.Condition = types.StringValue(string(requirementsItem.Condition)) + requirements1.DefinitionID = types.StringValue(requirementsItem.DefinitionID) + requirements1.Type = types.StringValue(string(requirementsItem.Type)) + if requirementsCount+1 > len(steps1.Requirements) { + steps1.Requirements = append(steps1.Requirements, requirements1) + } else { + steps1.Requirements[requirementsCount].Condition = requirements1.Condition + steps1.Requirements[requirementsCount].DefinitionID = requirements1.DefinitionID + steps1.Requirements[requirementsCount].Type = requirements1.Type + } + } + steps1.Type = types.StringValue(string(stepsItem.Type)) + steps1.UserIds = []types.Number{} + for _, v := range stepsItem.UserIds { + steps1.UserIds = append(steps1.UserIds, types.NumberValue(big.NewFloat(float64(v)))) + } + if stepsCount+1 > len(flow1.Section.Steps) { + flow1.Section.Steps = append(flow1.Section.Steps, steps1) + } else { + flow1.Section.Steps[stepsCount].AssignedTo = steps1.AssignedTo + flow1.Section.Steps[stepsCount].AutomationConfig = steps1.AutomationConfig + flow1.Section.Steps[stepsCount].Description = steps1.Description + flow1.Section.Steps[stepsCount].DueDate = steps1.DueDate + flow1.Section.Steps[stepsCount].DynamicDueDate = steps1.DynamicDueDate + flow1.Section.Steps[stepsCount].Ecp = steps1.Ecp + flow1.Section.Steps[stepsCount].ExecutionType = steps1.ExecutionType + flow1.Section.Steps[stepsCount].ID = steps1.ID + flow1.Section.Steps[stepsCount].Installer = steps1.Installer + flow1.Section.Steps[stepsCount].Journey = steps1.Journey + flow1.Section.Steps[stepsCount].Name = steps1.Name + flow1.Section.Steps[stepsCount].Order = steps1.Order + flow1.Section.Steps[stepsCount].Requirements = steps1.Requirements + flow1.Section.Steps[stepsCount].Type = steps1.Type + flow1.Section.Steps[stepsCount].UserIds = steps1.UserIds + } + } + flow1.Section.Type = types.StringValue(string(flowItem.Section.Type)) + } + if flowItem.Step != nil { + flow1.Step = &tfTypes.Step{} + flow1.Step.AssignedTo = []types.String{} + for _, v := range flowItem.Step.AssignedTo { + flow1.Step.AssignedTo = append(flow1.Step.AssignedTo, types.StringValue(v)) + } + if flowItem.Step.AutomationConfig == nil { + flow1.Step.AutomationConfig = nil + } else { + flow1.Step.AutomationConfig = &tfTypes.AutomationConfig{} + flow1.Step.AutomationConfig.FlowID = types.StringValue(flowItem.Step.AutomationConfig.FlowID) + } + if flowItem.Step.Description == nil { + flow1.Step.Description = nil + } else { + flow1.Step.Description = &tfTypes.StepDescription{} + flow1.Step.Description.Enabled = types.BoolPointerValue(flowItem.Step.Description.Enabled) + flow1.Step.Description.Value = types.StringPointerValue(flowItem.Step.Description.Value) + } + flow1.Step.DueDate = types.StringPointerValue(flowItem.Step.DueDate) + if flowItem.Step.DynamicDueDate == nil { + flow1.Step.DynamicDueDate = nil + } else { + flow1.Step.DynamicDueDate = &tfTypes.DynamicDueDate{} + flow1.Step.DynamicDueDate.ActionTypeCondition = types.StringValue(string(flowItem.Step.DynamicDueDate.ActionTypeCondition)) + flow1.Step.DynamicDueDate.NumberOfUnits = types.NumberValue(big.NewFloat(float64(flowItem.Step.DynamicDueDate.NumberOfUnits))) + flow1.Step.DynamicDueDate.StepID = types.StringPointerValue(flowItem.Step.DynamicDueDate.StepID) + flow1.Step.DynamicDueDate.TimePeriod = types.StringValue(string(flowItem.Step.DynamicDueDate.TimePeriod)) + } + if flowItem.Step.Ecp == nil { + flow1.Step.Ecp = nil + } else { + flow1.Step.Ecp = &tfTypes.ECPDetails{} + flow1.Step.Ecp.Description = types.StringPointerValue(flowItem.Step.Ecp.Description) + flow1.Step.Ecp.Enabled = types.BoolPointerValue(flowItem.Step.Ecp.Enabled) + if flowItem.Step.Ecp.Journey == nil { + flow1.Step.Ecp.Journey = nil + } else { + flow1.Step.Ecp.Journey = &tfTypes.StepJourney{} + flow1.Step.Ecp.Journey.ID = types.StringPointerValue(flowItem.Step.Ecp.Journey.ID) + flow1.Step.Ecp.Journey.JourneyID = types.StringPointerValue(flowItem.Step.Ecp.Journey.JourneyID) + flow1.Step.Ecp.Journey.Name = types.StringPointerValue(flowItem.Step.Ecp.Journey.Name) + } + flow1.Step.Ecp.Label = types.StringPointerValue(flowItem.Step.Ecp.Label) + } + if flowItem.Step.ExecutionType != nil { + flow1.Step.ExecutionType = types.StringValue(string(*flowItem.Step.ExecutionType)) + } else { + flow1.Step.ExecutionType = types.StringNull() + } + flow1.Step.ID = types.StringPointerValue(flowItem.Step.ID) + if flowItem.Step.Installer == nil { + flow1.Step.Installer = nil + } else { + flow1.Step.Installer = &tfTypes.ECPDetails{} + flow1.Step.Installer.Description = types.StringPointerValue(flowItem.Step.Installer.Description) + flow1.Step.Installer.Enabled = types.BoolPointerValue(flowItem.Step.Installer.Enabled) + if flowItem.Step.Installer.Journey == nil { + flow1.Step.Installer.Journey = nil + } else { + flow1.Step.Installer.Journey = &tfTypes.StepJourney{} + flow1.Step.Installer.Journey.ID = types.StringPointerValue(flowItem.Step.Installer.Journey.ID) + flow1.Step.Installer.Journey.JourneyID = types.StringPointerValue(flowItem.Step.Installer.Journey.JourneyID) + flow1.Step.Installer.Journey.Name = types.StringPointerValue(flowItem.Step.Installer.Journey.Name) + } + flow1.Step.Installer.Label = types.StringPointerValue(flowItem.Step.Installer.Label) + } + if flowItem.Step.Journey == nil { + flow1.Step.Journey = nil + } else { + flow1.Step.Journey = &tfTypes.StepJourney{} + flow1.Step.Journey.ID = types.StringPointerValue(flowItem.Step.Journey.ID) + flow1.Step.Journey.JourneyID = types.StringPointerValue(flowItem.Step.Journey.JourneyID) + flow1.Step.Journey.Name = types.StringPointerValue(flowItem.Step.Journey.Name) + } + flow1.Step.Name = types.StringValue(flowItem.Step.Name) + flow1.Step.Order = types.NumberValue(big.NewFloat(float64(flowItem.Step.Order))) + flow1.Step.Requirements = []tfTypes.StepRequirement{} + for requirementsCount1, requirementsItem1 := range flowItem.Step.Requirements { + var requirements3 tfTypes.StepRequirement + requirements3.Condition = types.StringValue(string(requirementsItem1.Condition)) + requirements3.DefinitionID = types.StringValue(requirementsItem1.DefinitionID) + requirements3.Type = types.StringValue(string(requirementsItem1.Type)) + if requirementsCount1+1 > len(flow1.Step.Requirements) { + flow1.Step.Requirements = append(flow1.Step.Requirements, requirements3) + } else { + flow1.Step.Requirements[requirementsCount1].Condition = requirements3.Condition + flow1.Step.Requirements[requirementsCount1].DefinitionID = requirements3.DefinitionID + flow1.Step.Requirements[requirementsCount1].Type = requirements3.Type + } + } + flow1.Step.Type = types.StringValue(string(flowItem.Step.Type)) + flow1.Step.UserIds = []types.Number{} + for _, v := range flowItem.Step.UserIds { + flow1.Step.UserIds = append(flow1.Step.UserIds, types.NumberValue(big.NewFloat(float64(v)))) + } + } + if flowCount+1 > len(r.Flow) { + r.Flow = append(r.Flow, flow1) + } else { + r.Flow[flowCount].Section = flow1.Section + r.Flow[flowCount].Step = flow1.Step + } + } + r.ID = types.StringPointerValue(resp.ID) + r.LastUpdateTime = types.StringPointerValue(resp.LastUpdateTime) + r.Name = types.StringValue(resp.Name) + r.UpdateEntityAttributes = []tfTypes.UpdateEntityAttributes{} + if len(r.UpdateEntityAttributes) > len(resp.UpdateEntityAttributes) { + r.UpdateEntityAttributes = r.UpdateEntityAttributes[:len(resp.UpdateEntityAttributes)] + } + for updateEntityAttributesCount, updateEntityAttributesItem := range resp.UpdateEntityAttributes { + var updateEntityAttributes1 tfTypes.UpdateEntityAttributes + updateEntityAttributes1.Source = types.StringValue(string(updateEntityAttributesItem.Source)) + updateEntityAttributes1.Target.EntityAttribute = types.StringValue(updateEntityAttributesItem.Target.EntityAttribute) + updateEntityAttributes1.Target.EntitySchema = types.StringValue(updateEntityAttributesItem.Target.EntitySchema) + if updateEntityAttributesCount+1 > len(r.UpdateEntityAttributes) { + r.UpdateEntityAttributes = append(r.UpdateEntityAttributes, updateEntityAttributes1) + } else { + r.UpdateEntityAttributes[updateEntityAttributesCount].Source = updateEntityAttributes1.Source + r.UpdateEntityAttributes[updateEntityAttributesCount].Target = updateEntityAttributes1.Target + } + } + r.UserIds = []types.Number{} + for _, v := range resp.UserIds { + r.UserIds = append(r.UserIds, types.NumberValue(big.NewFloat(float64(v)))) + } + } +} diff --git a/internal/sdk/closingreason.go b/internal/sdk/closingreason.go deleted file mode 100644 index fa91379..0000000 --- a/internal/sdk/closingreason.go +++ /dev/null @@ -1,316 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package sdk - -import ( - "bytes" - "context" - "fmt" - "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/internal/hooks" - "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/internal/utils" - "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/models/errors" - "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/models/operations" - "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/models/shared" - "io" - "net/http" - "net/url" -) - -type ClosingReason struct { - sdkConfiguration sdkConfiguration -} - -func newClosingReason(sdkConfig sdkConfiguration) *ClosingReason { - return &ClosingReason{ - sdkConfiguration: sdkConfig, - } -} - -// ChangeReasonStatus - changeReasonStatus -// Change the status of a Closing Reason (eg. ACTIVE to INACTIVE). -func (s *ClosingReason) ChangeReasonStatus(ctx context.Context, request operations.ChangeReasonStatusRequest) (*operations.ChangeReasonStatusResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "changeReasonStatus", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) - opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/workflows/closing-reasons/{reasonId}", request, nil) - if err != nil { - return nil, fmt.Errorf("error generating URL: %w", err) - } - - bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "ChangeReasonStatusReq", "json", `request:"mediaType=application/json"`) - if err != nil { - return nil, err - } - - req, err := http.NewRequestWithContext(ctx, "PATCH", opURL, bodyReader) - if err != nil { - return nil, fmt.Errorf("error creating request: %w", err) - } - req.Header.Set("Accept", "application/json") - req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) - - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { - return nil, err - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, err - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } - } - - res := &operations.ChangeReasonStatusResponse{ - StatusCode: httpRes.StatusCode, - ContentType: httpRes.Header.Get("Content-Type"), - RawResponse: httpRes, - } - - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - - switch { - case httpRes.StatusCode == 202: - case httpRes.StatusCode == 400: - fallthrough - case httpRes.StatusCode == 500: - switch { - case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): - var out shared.ErrorResp - if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { - return nil, err - } - - res.ErrorResp = &out - default: - return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) - } - default: - return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) - } - - return res, nil - -} - -// CreateClosingReason - createClosingReason -// A created Closing Reason is stored for the organization and will be displayed in the library of reasons. -func (s *ClosingReason) CreateClosingReason(ctx context.Context, request shared.ClosingReason) (*operations.CreateClosingReasonResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "createClosingReason", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) - opURL, err := url.JoinPath(baseURL, "/v1/workflows/closing-reasons") - if err != nil { - return nil, fmt.Errorf("error generating URL: %w", err) - } - - bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`) - if err != nil { - return nil, err - } - - req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader) - if err != nil { - return nil, fmt.Errorf("error creating request: %w", err) - } - req.Header.Set("Accept", "application/json") - req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) - - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { - return nil, err - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, err - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } - } - - res := &operations.CreateClosingReasonResponse{ - StatusCode: httpRes.StatusCode, - ContentType: httpRes.Header.Get("Content-Type"), - RawResponse: httpRes, - } - - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - - switch { - case httpRes.StatusCode == 201: - switch { - case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): - var out shared.ClosingReason - if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { - return nil, err - } - - res.ClosingReason = &out - default: - return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) - } - default: - return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) - } - - return res, nil - -} - -// GetAllClosingReasons - getAllClosingReasons -// Get all Closing Reasons defined in the organization by default all Active. -func (s *ClosingReason) GetAllClosingReasons(ctx context.Context, request operations.GetAllClosingReasonsRequest) (*operations.GetAllClosingReasonsResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "getAllClosingReasons", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) - opURL, err := url.JoinPath(baseURL, "/v1/workflows/closing-reasons") - if err != nil { - return nil, fmt.Errorf("error generating URL: %w", err) - } - - req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil) - if err != nil { - return nil, fmt.Errorf("error creating request: %w", err) - } - req.Header.Set("Accept", "application/json") - req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - - if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { - return nil, fmt.Errorf("error populating query params: %w", err) - } - - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { - return nil, err - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, err - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } - } - - res := &operations.GetAllClosingReasonsResponse{ - StatusCode: httpRes.StatusCode, - ContentType: httpRes.Header.Get("Content-Type"), - RawResponse: httpRes, - } - - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - - switch { - case httpRes.StatusCode == 200: - switch { - case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): - var out shared.ClosingReasons - if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { - return nil, err - } - - res.ClosingReasons = &out - default: - return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) - } - default: - return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) - } - - return res, nil - -} diff --git a/internal/sdk/models/operations/changereasonstatus.go b/internal/sdk/models/operations/changereasonstatus.go deleted file mode 100644 index b45075f..0000000 --- a/internal/sdk/models/operations/changereasonstatus.go +++ /dev/null @@ -1,67 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package operations - -import ( - "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/models/shared" - "net/http" -) - -type ChangeReasonStatusRequest struct { - // change the status of a closing reason - ChangeReasonStatusReq *shared.ChangeReasonStatusReq `request:"mediaType=application/json"` - ReasonID string `pathParam:"style=simple,explode=false,name=reasonId"` -} - -func (o *ChangeReasonStatusRequest) GetChangeReasonStatusReq() *shared.ChangeReasonStatusReq { - if o == nil { - return nil - } - return o.ChangeReasonStatusReq -} - -func (o *ChangeReasonStatusRequest) GetReasonID() string { - if o == nil { - return "" - } - return o.ReasonID -} - -type ChangeReasonStatusResponse struct { - // HTTP response content type for this operation - ContentType string - // bad request - ErrorResp *shared.ErrorResp - // HTTP response status code for this operation - StatusCode int - // Raw HTTP response; suitable for custom response parsing - RawResponse *http.Response -} - -func (o *ChangeReasonStatusResponse) GetContentType() string { - if o == nil { - return "" - } - return o.ContentType -} - -func (o *ChangeReasonStatusResponse) GetErrorResp() *shared.ErrorResp { - if o == nil { - return nil - } - return o.ErrorResp -} - -func (o *ChangeReasonStatusResponse) GetStatusCode() int { - if o == nil { - return 0 - } - return o.StatusCode -} - -func (o *ChangeReasonStatusResponse) GetRawResponse() *http.Response { - if o == nil { - return nil - } - return o.RawResponse -} diff --git a/internal/sdk/models/operations/createclosingreason.go b/internal/sdk/models/operations/createclosingreason.go deleted file mode 100644 index ef73c2d..0000000 --- a/internal/sdk/models/operations/createclosingreason.go +++ /dev/null @@ -1,47 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package operations - -import ( - "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/models/shared" - "net/http" -) - -type CreateClosingReasonResponse struct { - // closing reason is stored successfully in the repository - ClosingReason *shared.ClosingReason - // HTTP response content type for this operation - ContentType string - // HTTP response status code for this operation - StatusCode int - // Raw HTTP response; suitable for custom response parsing - RawResponse *http.Response -} - -func (o *CreateClosingReasonResponse) GetClosingReason() *shared.ClosingReason { - if o == nil { - return nil - } - return o.ClosingReason -} - -func (o *CreateClosingReasonResponse) GetContentType() string { - if o == nil { - return "" - } - return o.ContentType -} - -func (o *CreateClosingReasonResponse) GetStatusCode() int { - if o == nil { - return 0 - } - return o.StatusCode -} - -func (o *CreateClosingReasonResponse) GetRawResponse() *http.Response { - if o == nil { - return nil - } - return o.RawResponse -} diff --git a/internal/sdk/models/operations/getallclosingreasons.go b/internal/sdk/models/operations/getallclosingreasons.go deleted file mode 100644 index 5ce3f2b..0000000 --- a/internal/sdk/models/operations/getallclosingreasons.go +++ /dev/null @@ -1,59 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package operations - -import ( - "github.com/epilot-dev/terraform-provider-epilot-workflow/internal/sdk/models/shared" - "net/http" -) - -type GetAllClosingReasonsRequest struct { - // Filter Closing Reasons by status like active inactiv - IncludeInactive *bool `queryParam:"style=form,explode=true,name=includeInactive"` -} - -func (o *GetAllClosingReasonsRequest) GetIncludeInactive() *bool { - if o == nil { - return nil - } - return o.IncludeInactive -} - -type GetAllClosingReasonsResponse struct { - // Returns the entire catalog of closing reasons per organization - ClosingReasons *shared.ClosingReasons - // HTTP response content type for this operation - ContentType string - // HTTP response status code for this operation - StatusCode int - // Raw HTTP response; suitable for custom response parsing - RawResponse *http.Response -} - -func (o *GetAllClosingReasonsResponse) GetClosingReasons() *shared.ClosingReasons { - if o == nil { - return nil - } - return o.ClosingReasons -} - -func (o *GetAllClosingReasonsResponse) GetContentType() string { - if o == nil { - return "" - } - return o.ContentType -} - -func (o *GetAllClosingReasonsResponse) GetStatusCode() int { - if o == nil { - return 0 - } - return o.StatusCode -} - -func (o *GetAllClosingReasonsResponse) GetRawResponse() *http.Response { - if o == nil { - return nil - } - return o.RawResponse -} diff --git a/internal/sdk/models/shared/changereasonstatusreq.go b/internal/sdk/models/shared/changereasonstatusreq.go deleted file mode 100644 index 13efcf3..0000000 --- a/internal/sdk/models/shared/changereasonstatusreq.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package shared - -type ChangeReasonStatusReq struct { - Status ClosingReasonsStatus `json:"status"` -} - -func (o *ChangeReasonStatusReq) GetStatus() ClosingReasonsStatus { - if o == nil { - return ClosingReasonsStatus("") - } - return o.Status -} diff --git a/internal/sdk/models/shared/closingreason.go b/internal/sdk/models/shared/closingreason.go deleted file mode 100644 index 1ab2a92..0000000 --- a/internal/sdk/models/shared/closingreason.go +++ /dev/null @@ -1,47 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package shared - -// ClosingReason - One Closing reason for a workflow -type ClosingReason struct { - CreationTime *string `json:"creationTime,omitempty"` - ID *string `json:"id,omitempty"` - LastUpdateTime *string `json:"lastUpdateTime,omitempty"` - Status ClosingReasonsStatus `json:"status"` - Title string `json:"title"` -} - -func (o *ClosingReason) GetCreationTime() *string { - if o == nil { - return nil - } - return o.CreationTime -} - -func (o *ClosingReason) GetID() *string { - if o == nil { - return nil - } - return o.ID -} - -func (o *ClosingReason) GetLastUpdateTime() *string { - if o == nil { - return nil - } - return o.LastUpdateTime -} - -func (o *ClosingReason) GetStatus() ClosingReasonsStatus { - if o == nil { - return ClosingReasonsStatus("") - } - return o.Status -} - -func (o *ClosingReason) GetTitle() string { - if o == nil { - return "" - } - return o.Title -} diff --git a/internal/sdk/models/shared/closingreasons.go b/internal/sdk/models/shared/closingreasons.go deleted file mode 100644 index 784e495..0000000 --- a/internal/sdk/models/shared/closingreasons.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package shared - -type ClosingReasons struct { - Reasons []ClosingReason `json:"reasons"` -} - -func (o *ClosingReasons) GetReasons() []ClosingReason { - if o == nil { - return []ClosingReason{} - } - return o.Reasons -} diff --git a/internal/sdk/models/shared/closingreasonsstatus.go b/internal/sdk/models/shared/closingreasonsstatus.go deleted file mode 100644 index a053743..0000000 --- a/internal/sdk/models/shared/closingreasonsstatus.go +++ /dev/null @@ -1,34 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package shared - -import ( - "encoding/json" - "fmt" -) - -type ClosingReasonsStatus string - -const ( - ClosingReasonsStatusActive ClosingReasonsStatus = "ACTIVE" - ClosingReasonsStatusInactive ClosingReasonsStatus = "INACTIVE" -) - -func (e ClosingReasonsStatus) ToPointer() *ClosingReasonsStatus { - return &e -} -func (e *ClosingReasonsStatus) UnmarshalJSON(data []byte) error { - var v string - if err := json.Unmarshal(data, &v); err != nil { - return err - } - switch v { - case "ACTIVE": - fallthrough - case "INACTIVE": - *e = ClosingReasonsStatus(v) - return nil - default: - return fmt.Errorf("invalid value for ClosingReasonsStatus: %v", v) - } -} diff --git a/internal/sdk/sdk.go b/internal/sdk/sdk.go index 62c385c..60dc8dd 100644 --- a/internal/sdk/sdk.go +++ b/internal/sdk/sdk.go @@ -64,8 +64,7 @@ func (c *sdkConfiguration) GetServerDetails() (string, map[string]string) { // SDK - Workflows Definitions: Service for Workflow Definitions for different processes inside of an Organization type SDK struct { - ClosingReason *ClosingReason - Workflows *Workflows + Workflows *Workflows sdkConfiguration sdkConfiguration } @@ -158,8 +157,6 @@ func New(opts ...SDKOption) *SDK { sdk.sdkConfiguration.ServerURL = serverURL } - sdk.ClosingReason = newClosingReason(sdk.sdkConfiguration) - sdk.Workflows = newWorkflows(sdk.sdkConfiguration) return sdk