using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Monitoring.Core.Domain.EventManagement;

namespace Monitoring.Infrastructure.Data.Configurations;

public class AlarmScopeConfiguration : IEntityTypeConfiguration<AlarmScope>
{
	public void Configure(EntityTypeBuilder<AlarmScope> builder)
	{
		_ = builder.HasKey(x => x.Id);
		_ = builder
			.Property(x => x.Id)
			.IsRequired()
			.HasConversion(x => x.Value, x => new AlarmScopeId(x));

		_ = builder
			.HasOne(x => x.Asset)
			.WithMany(x => x.AlarmScopes)
			.HasForeignKey(x => x.AssetId)
			.IsRequired()
			.OnDelete(DeleteBehavior.Cascade);
		_ = builder.Property(x => x.AssetId).HasConversion(x => x.Value, x => new(x));

		_ = builder.Property(x => x.Result).IsRequired();
	}
}
