func getCommands(coffeeHouseConfig *CoffeeHouseConfiguration, isFirst, isActive bool) *[]s.OutCommand { drinkString, drinkFields := getCommandsTextAndFieldForDrink(coffeeHouseConfig) commands := []s.OutCommand{ s.OutCommand{ Title: "Напитки", Action: "order_drink", Position: 0, Repeated: true, Form: &s.OutForm{ Title: "Заказ напитка", Type: "form", Name: "order_drink_form", Text: drinkString, Fields: drinkFields, }, }, s.OutCommand{ Title: "Выпечка", Action: "order_bake", Position: 1, Form: &s.OutForm{ Title: "Заказ выпечки", Type: "form", Name: "order_bake_form", Text: "Ваш заказ: ?(bake), ?(count) ?(to_time)", Fields: []s.OutField{ s.OutField{ Name: "bake", Type: "list-single", Attributes: s.FieldAttribute{ Label: "выпечка", Required: true, }, Items: s.FormItemsFromSortedWithPrice(coffeeHouseConfig.Bakes), }, s.OutField{ Name: "count", Type: "list-single", Attributes: s.FieldAttribute{ Label: "количество", Required: false, EmptyText: &ONE, }, Items: s.FormItems([]string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}), }, s.OutField{ Name: "to_time", Type: "list-single", Attributes: s.FieldAttribute{ Label: "когда", Required: false, EmptyText: &NOW, }, Items: s.FormItems([]string{"через 10 минут", "через 20 минут", "через 30 минут"}), }, }, }, }, } position := 1 if !isFirst { position += 1 commands = append(commands, s.OutCommand{ Title: "Повторить предыдущий заказ", Action: "repeat", Position: position, }, ) } if isActive { position += 1 commands = append(commands, s.OutCommand{ Title: "Отменить текущий заказ", Action: "cancel", Position: position, }, ) } return &commands }
func getCommandsTextAndFieldForDrink(chc *CoffeeHouseConfiguration) (string, []s.OutField) { result := "Ваш заказ: ?(drink)" resultFields := []s.OutField{ s.OutField{ Name: "drink", Type: "list-single", Attributes: s.FieldAttribute{ Label: "напиток", Required: true, }, Items: s.FormItemsFromSortedWithPrice(chc.Drinks), }, s.OutField{ Name: "sugar", Type: "list-single", Attributes: s.FieldAttribute{ Label: "сахар", Required: false, EmptyText: &NO_SUGAR, }, Items: s.FormItems([]string{"1 ложка", "2 ложки", "3 ложки", "4 ложки"}), }, s.OutField{ Name: "count", Type: "list-single", Attributes: s.FieldAttribute{ Label: "количество", Required: false, EmptyText: &ONE, }, Items: s.FormItems([]string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}), }, s.OutField{ Name: "to_time", Type: "list-single", Attributes: s.FieldAttribute{ Label: "когда", Required: false, EmptyText: &NOW, }, Items: s.FormItems([]string{"через 10 минут", "через 20 минут", "через 30 минут"}), }, } if len(chc.Additives) > 0 { result = fmt.Sprintf("%v, ?(additive)", result) resultFields = append(resultFields, s.OutField{ Name: "additive", Type: "list-single", Attributes: s.FieldAttribute{ Label: "добавки", Required: false, EmptyText: &NO_ADD, }, Items: s.FormItemsFromSortedWithPrice(chc.Additives), }) } if len(chc.Syrups) > 0 { result = fmt.Sprintf("%v, ?(syrup),", result) resultFields = append(resultFields, s.OutField{ Name: "syrup", Type: "list-single", Attributes: s.FieldAttribute{ Label: "сироп", Required: false, EmptyText: &NO_SYRUP, }, Items: s.FormItemsFromSortedWithPrice(chc.Syrups), }) } result = fmt.Sprintf("%v ?(sugar), ?(count) ?(to_time)", result) return result, resultFields }