using MyService.Domain.SeedWork;
namespace MyService.Domain.AggregatesModel.SampleAggregate;
///
/// EN: Sample status enumeration following type-safe enum pattern.
/// VI: Enumeration trạng thái Sample theo pattern enum an toàn kiểu.
///
public class SampleStatus : Enumeration
{
///
/// EN: Draft status - initial state
/// VI: Trạng thái nháp - trạng thái ban đầu
///
public static SampleStatus Draft = new(1, nameof(Draft));
///
/// EN: Active status - ready for use
/// VI: Trạng thái hoạt động - sẵn sàng sử dụng
///
public static SampleStatus Active = new(2, nameof(Active));
///
/// EN: Completed status - finished processing
/// VI: Trạng thái hoàn thành - đã xử lý xong
///
public static SampleStatus Completed = new(3, nameof(Completed));
///
/// EN: Cancelled status - cancelled by user
/// VI: Trạng thái đã hủy - bị hủy bởi người dùng
///
public static SampleStatus Cancelled = new(4, nameof(Cancelled));
public SampleStatus(int id, string name) : base(id, name)
{
}
///
/// EN: Get all available statuses.
/// VI: Lấy tất cả các trạng thái có sẵn.
///
public static IEnumerable List() => GetAll();
///
/// EN: Parse status from name.
/// VI: Parse trạng thái từ tên.
///
public static SampleStatus FromName(string name)
{
var status = List().SingleOrDefault(s =>
string.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
if (status is null)
{
throw new ArgumentException($"Possible values for SampleStatus: {string.Join(",", List().Select(s => s.Name))}");
}
return status;
}
///
/// EN: Parse status from ID.
/// VI: Parse trạng thái từ ID.
///
public static SampleStatus From(int id)
{
var status = List().SingleOrDefault(s => s.Id == id);
if (status is null)
{
throw new ArgumentException($"Possible values for SampleStatus: {string.Join(",", List().Select(s => s.Name))}");
}
return status;
}
}