using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
namespace AI.Models.Form
{
///
/// 表单字段条目:schema + 当前值,用于绑定与提交
///
public class FormFieldEntry : INotifyPropertyChanged
{
private string _currentValue = string.Empty;
public string Id { get; set; } = string.Empty;
public string Label { get; set; } = string.Empty;
/// 可选描述/提示
public string? Description { get; set; }
public FormFieldType Type { get; set; }
public bool Required { get; set; }
public object? DefaultValue { get; set; }
public List? Options { get; set; }
// ----- number -----
public double? Min { get; set; }
public double? Max { get; set; }
public double? Step { get; set; }
// ----- string -----
public int? MaxLength { get; set; }
public string? Placeholder { get; set; }
// ----- multi-select -----
public List? DefaultValues { get; set; }
/// 多选当前选中项(MultiSelect 绑定用)
public ObservableCollection SelectedValues { get; } = new ObservableCollection();
/// 多选选项列表(用于绑定 CheckBox 列表,与 SelectedValues 同步)
public ObservableCollection MultiSelectOptions { get; } = new ObservableCollection();
/// 当前输入值(绑定用,提交时按 Type 转换)
public string CurrentValue
{
get => _currentValue;
set => SetProperty(ref _currentValue, value);
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
protected bool SetProperty(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer.Default.Equals(field, value))
return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
}