module Ecoportal module API class GraphQL module Input module LocationStructure class ApplyCommands < Ecoportal::API::GraphQL::Base::Model passkey :id passthrough :clientMutationId passboolean :force embeds_many :commands, klass: Ecoportal::API::GraphQL::Input::LocationStructure::CommandInterface passboolean :preview def add(type, **kargs) if (command = new_command(type)) command.set_values(**kargs) unless kargs.empty? yield(command) if block_given? end command end private def new_command(type) case type when :archive Input::LocationStructure::ArchiveCommand.new when :unarchive Input::LocationStructure::UnarchiveCommand.new when :delete Input::LocationStructure::DeleteCommand.new when :move Input::LocationStructure::MoveCommand.new when :insert Input::LocationStructure::InsertCommand.new when :update Input::LocationStructure::UpdateCommand.new when :reoder Input::LocationStructure::ReoderCommand.new else raise "Unknown command type: '#{type}'" end end end end end end end end