projectionCopyConfigOptionsWithGuard function
List<ChatConfigOption>
projectionCopyConfigOptionsWithGuard(
- Object? rawOptions,
- ChatStructuredUpdateGuard guard, {
- required String field,
Implementation
List<ChatConfigOption> projectionCopyConfigOptionsWithGuard(
Object? rawOptions,
acp.ChatStructuredUpdateGuard guard, {
required String field,
}) {
if (rawOptions is! List) {
throw const FormatException('Invalid config options collection.');
}
final optionCount = guard.checkCollection(rawOptions, field: field);
guard.consumeContainerNode(field: field);
final copiedOptions = <ChatConfigOption>[];
for (var optionIndex = 0; optionIndex < optionCount; optionIndex += 1) {
final Object? rawOption;
try {
rawOption = rawOptions[optionIndex];
} on Object {
throw const FormatException('Invalid chat message config option access.');
}
if (rawOption is! ChatConfigOption) {
throw const FormatException('Invalid chat message config option.');
}
guard.consumeEntry(field: 'config option');
final rawChoices = rawOption.options;
final choiceCount = guard.checkCollection(
rawChoices,
field: 'config option choices',
);
guard.consumeContainerNode(field: 'config option choices');
final copiedChoices = <ChatConfigOptionChoice>[];
for (var choiceIndex = 0; choiceIndex < choiceCount; choiceIndex += 1) {
final choice = rawChoices[choiceIndex];
guard.consumeEntry(field: 'config option choice');
copiedChoices.add(
ChatConfigOptionChoice(
value: guard.copyString(
choice.value,
field: 'config option choice value',
),
name: guard.copyString(
choice.name,
field: 'config option choice name',
),
description: choice.description == null
? null
: guard.copyString(
choice.description,
field: 'config option choice description',
),
),
);
}
if (rawChoices.length != choiceCount) {
throw const FormatException('Invalid config option choice count.');
}
copiedOptions.add(
ChatConfigOption(
id: guard.copyString(rawOption.id, field: 'config option id'),
name: guard.copyString(rawOption.name, field: 'config option name'),
type: guard.copyString(rawOption.type, field: 'config option type'),
currentValue: guard.copyString(
rawOption.currentValue,
field: 'config option current value',
),
options: List<ChatConfigOptionChoice>.unmodifiable(copiedChoices),
description: rawOption.description == null
? null
: guard.copyString(
rawOption.description,
field: 'config option description',
),
category: rawOption.category == null
? null
: guard.copyString(
rawOption.category,
field: 'config option category',
),
group: rawOption.group == null
? null
: guard.copyString(rawOption.group, field: 'config option group'),
),
);
}
if (rawOptions.length != optionCount) {
throw const FormatException('Invalid config option count.');
}
return List<ChatConfigOption>.unmodifiable(copiedOptions);
}