using Microsoft.EntityFrameworkCore;

using Monitoring.Core.Domain.EventManagement;

namespace Monitoring.Infrastructure.Data.Configurations;

public class EventCodeConfiguration : IEntityTypeConfiguration<EventCode>
{
	public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder<EventCode> builder)
	{
		_ = builder.HasKey(x => x.Id);
		_ = builder.Property(x => x.Id)
			.IsRequired()
			.HasConversion(x => x.Value, x => new(x));

		_ = builder.Property(x => x.Value)
			.IsRequired()
			.HasConversion(x => x.Value, x => new(x));
		_ = builder.HasIndex(x => x.Value)
			.IsUnique();

		_ = builder.Property(x => x.Group);
		_ = builder.HasIndex(x => x.Group);

		_ = builder.Property(x => x.IsActive);
	}
}
