Files
GreenHomeBack/src/GreenHome.Domain/DeviceRelay.cs
2026-09-11 23:52:11 +03:30

137 lines
4.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace GreenHome.Domain;
/// <summary>
/// نوع مصرف‌کننده متصل به رله
/// </summary>
public enum RelayKind
{
/// <summary>سایر / نامشخص</summary>
Generic = 0,
/// <summary>فن</summary>
Fan = 1,
/// <summary>هیتر / بخاری</summary>
Heater = 2,
/// <summary>پمپ آب</summary>
WaterPump = 3,
/// <summary>مه‌پاش / رطوبت‌ساز</summary>
Humidifier = 4,
/// <summary>روشنایی</summary>
Light = 5,
/// <summary>شیر برقی</summary>
Valve = 6
}
/// <summary>
/// نوع اقدام یک قانون رله
/// </summary>
public enum RelayAction
{
/// <summary>روشن کردن</summary>
On = 0,
/// <summary>خاموش کردن</summary>
Off = 1
}
/// <summary>
/// رله دستگاه به همراه تنظیمات آن
/// </summary>
public sealed class DeviceRelay
{
public int Id { get; set; }
public int DeviceSettingsId { get; set; }
public DeviceSettings DeviceSettings { get; set; } = null!;
/// <summary>شماره رله (۱ تا RelayCount)</summary>
public int RelayIndex { get; set; }
/// <summary>نام نمایشی رله (مثلاً فن، هیتر)</summary>
public string Name { get; set; } = string.Empty;
/// <summary>آیا این رله فعال است؟</summary>
public bool IsEnabled { get; set; } = true;
/// <summary>نوع مصرف‌کننده متصل به رله</summary>
public RelayKind RelayKind { get; set; } = RelayKind.Generic;
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
/// <summary>گروه‌های شرط روشن/خاموش شدن رله (گروه‌ها با OR ترکیب می‌شوند)</summary>
public ICollection<RelayRuleGroup> RuleGroups { get; set; } = new List<RelayRuleGroup>();
}
/// <summary>
/// یک گروه شرط برای روشن یا خاموش کردن رله.
/// داخل هر گروه شرایط با AND ترکیب می‌شوند؛ گروه‌های هم‌عمل با OR.
/// </summary>
public sealed class RelayRuleGroup
{
public int Id { get; set; }
public int DeviceRelayId { get; set; }
public DeviceRelay DeviceRelay { get; set; } = null!;
/// <summary>اقدام: روشن یا خاموش کردن رله</summary>
public RelayAction Action { get; set; } = RelayAction.On;
/// <summary>برچسب اختیاری گروه (مثلاً «ایمنی»، «خنک‌سازی») برای استفاده در لاگ/اعلان</summary>
public string? Label { get; set; }
/// <summary>ترتیب گروه‌ها</summary>
public int Order { get; set; }
/// <summary>شرایط داخل این گروه (AND)</summary>
public ICollection<RelayRuleCondition> Conditions { get; set; } = new List<RelayRuleCondition>();
}
/// <summary>
/// نوع یک شرط رله: سنسوری یا زمانی
/// </summary>
public enum RelayConditionType
{
Sensor = 0,
Time = 1
}
/// <summary>
/// یک شرط واحد داخل گروه (سنسوری یا بازه زمانی)
/// </summary>
public sealed class RelayRuleCondition
{
public int Id { get; set; }
public int RelayRuleGroupId { get; set; }
public RelayRuleGroup RelayRuleGroup { get; set; } = null!;
/// <summary>نوع شرط: سنسوری یا زمانی</summary>
public RelayConditionType ConditionType { get; set; } = RelayConditionType.Sensor;
// ---- شرط سنسوری ----
/// <summary>نوع سنسور: دما، رطوبت، خاک، گاز، نور</summary>
public SensorType? SensorType { get; set; }
/// <summary>نوع مقایسه: بزرگتر، کوچکتر، بین، خارج از محدوده</summary>
public ComparisonType? ComparisonType { get; set; }
/// <summary>مقدار عددی اول</summary>
public decimal? Value1 { get; set; }
/// <summary>مقدار عددی دوم (برای بین و خارج از محدوده)</summary>
public decimal? Value2 { get; set; }
// ---- شرط زمانی ----
/// <summary>شروع بازه به دقیقه از نیمه‌شب (۰ تا ۱۴۳۹)</summary>
public int? StartMinutes { get; set; }
/// <summary>پایان بازه به دقیقه از نیمه‌شب (۰ تا ۱۴۳۹) — اگر کوچک‌تر از شروع باشد یعنی از نیمه‌شب عبور می‌کند</summary>
public int? EndMinutes { get; set; }
/// <summary>ترتیب شرایط داخل گروه</summary>
public int Order { get; set; }
}