using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using Monitoring.Core.Domain;
using Monitoring.Core.Domain.AlarmCommentPrimitives;

namespace Monitoring.Infrastructure.Data.Configurations;

public class AlarmResetCommentConfiguration : IEntityTypeConfiguration<AlarmResetComment>
{
	public void Configure(EntityTypeBuilder<AlarmResetComment> builder)
	{
		_ = builder.HasKey(x => x.Id);
		_ = builder.Property(x => x.Id)
			.IsRequired()
			.HasConversion( id => id.Value, value => new AlarmResetCommentId(value));
		_ = builder.HasOne(x => x.Organization)
			.WithMany(x => x.AlarmResetComments)
			.HasForeignKey(x=>x.OrganizationId)
			.IsRequired()
			.OnDelete(DeleteBehavior.Cascade);
	}
}