namespace AIStudio.Assistants.BeyondFactsLab;
///
/// Whom of the list of participants the BeyondFacts Lab researches in depth, stored as research/participant-selection.json
/// in the folder of the step "Strategy".
///
///
/// A selection belongs to the list it was made for, see IsFor. While there is none for the current list, a short list
/// counts as selected as a whole, and a long one as not selected, see SelectedIn; for a long list, the lab suggests a
/// selection, see BflResearchRunner.SuggestSelectionAsync.
///
public sealed class BflParticipantSelection
{
///
/// The version of the stored form this version of AI Studio writes. Raise it with every new property.
///
public const int CURRENT_SCHEMA_VERSION = 1;
///
/// How many people the lab suggests at most. A list of no more people counts as selected as a whole.
///
public const int MAX_SUGGESTED_PEOPLE = 5;
///
/// Gets or sets the version of the stored form.
///
public int SchemaVersion { get; set; } = CURRENT_SCHEMA_VERSION;
///
/// Gets or sets the names of the selected people, as the list gives them.
///
public List Names { get; set; } = [];
///
/// Gets or sets who chose the people.
///
public BflParticipantSelectionSource Source { get; set; } = BflParticipantSelectionSource.PERSON;
///
/// Gets or sets when the list the selection was made for was researched, see BflResearch.CreatedAtUtc.
///
public DateTimeOffset ListCreatedAtUtc { get; set; }
///
/// Tells whether the selection was made for a list, and not for an earlier one.
///
/// The research on the participants.
public bool IsFor(BflResearch list) => this.ListCreatedAtUtc == list.CreatedAtUtc;
///
/// Gets the people of a list whom the lab researches in depth.
///
/// The research on the participants.
/// The stored selection, or null when there is none.
/// The people, in the order of the list.
public static IReadOnlyList SelectedIn(BflResearch list, BflParticipantSelection? selection)
{
if (selection is not null && selection.IsFor(list))
return [.. list.Participants.Where(participant => selection.Names.Any(participant.HasName))];
return list.Participants.Count <= MAX_SUGGESTED_PEOPLE ? list.Participants : [];
}
///
/// Tells whether the lab suggests whom of a list to research: when the list is long and nobody chose for it yet.
///
/// The research on the participants.
/// The stored selection, or null when there is none.
public static bool NeedsSuggestion(BflResearch list, BflParticipantSelection? selection) => list.Participants.Count > MAX_SUGGESTED_PEOPLE && (selection is null || !selection.IsFor(list));
}