using JdeScoping.DataSync.Configuration;
namespace JdeScoping.ConfigManager.ViewModels.PipelineSteps;
///
/// View model for the destination step in a pipeline.
///
public class DestinationStepViewModel : PipelineStepViewModelBase
{
private readonly DestinationElement _model;
///
/// Initializes a new instance of the class.
///
/// The destination configuration model.
/// Callback invoked when the destination configuration changes.
public DestinationStepViewModel(DestinationElement model, Action onChanged) : base(onChanged)
{
_model = model ?? throw new ArgumentNullException(nameof(model));
}
///
public override PipelineStepType StepType => PipelineStepType.Destination;
///
public override string DisplayName => "Destination";
///
public override string Icon => ""; // mdi-database
///
public override string Summary => !string.IsNullOrEmpty(Table) ? $"→ {Table}" : "(no table)";
///
/// Gets or sets the destination table name.
///
public string Table
{
get => _model.Table;
set
{
if (_model.Table != value)
{
_model.Table = value ?? string.Empty;
OnPropertyChanged();
OnPropertyChanged(nameof(Summary));
NotifyChanged();
}
}
}
///
/// Gets or sets the match columns as newline-separated text.
///
public string MatchColumnsText
{
get => string.Join("\n", _model.MatchColumns);
set
{
var columns = (value ?? string.Empty).Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList();
if (!_model.MatchColumns.SequenceEqual(columns))
{
_model.MatchColumns = columns;
OnPropertyChanged();
NotifyChanged();
}
}
}
///
/// Gets or sets the columns to exclude from updates as newline-separated text.
///
public string ExcludeFromUpdateText
{
get => string.Join("\n", _model.ExcludeFromUpdate);
set
{
var columns = (value ?? string.Empty).Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList();
if (!_model.ExcludeFromUpdate.SequenceEqual(columns))
{
_model.ExcludeFromUpdate = columns;
OnPropertyChanged();
NotifyChanged();
}
}
}
}