using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
using TeamAAS.Feeder.Enums;
using TeamAAS.Feeder.Models;
namespace TeamAAS.Feeder.Models
{
///
/// 供料器配方 —— 调试完成后保存的可复用参数集
/// 插件运行时只需 LoadRecipe → DownloadAllParams → 执行
///
public class FeederRecipe : INotifyPropertyChanged
{
private string _recipeName = "";
private string _description = "";
private FeederBrand _brand = FeederBrand.Team;
private DateTime _createdAt = DateTime.Now;
private DateTime _updatedAt = DateTime.Now;
[Category("配方信息"), DisplayName("配方名称")]
public string RecipeName
{
get { return _recipeName; }
set { SetProperty(ref _recipeName, value); }
}
[Category("配方信息"), DisplayName("描述")]
public string Description
{
get { return _description; }
set { SetProperty(ref _description, value); }
}
[Category("配方信息"), DisplayName("品牌")]
public FeederBrand Brand
{
get { return _brand; }
set { SetProperty(ref _brand, value); }
}
[Browsable(false)]
public DateTime CreatedAt
{
get { return _createdAt; }
set { SetProperty(ref _createdAt, value); }
}
[Browsable(false)]
public DateTime UpdatedAt
{
get { return _updatedAt; }
set { SetProperty(ref _updatedAt, value); }
}
///
/// 11 个振动动作组参数(A~K,对应 FeederAction 0~10)
///
public ObservableCollection ActionGroups { get; set; }
= new ObservableCollection(
Enumerable.Range(0, 11).Select(_ => new SingleActionParam()));
///
/// 多个送料流程(序列集),可选
///
public ObservableCollection Sequences { get; set; }
= new ObservableCollection();
public FeederRecipe Clone()
{
var json = JsonConvert.SerializeObject(this);
return JsonConvert.DeserializeObject(json);
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer.Default.Equals(storage, value)) return false;
storage = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
return true;
}
}
}