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

namespace Monitoring.Infrastructure.Data.Configurations;

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

		_ = builder
			.HasOne(x => x.Template)
			.WithMany()
			.HasForeignKey(x => x.TemplateId)
			.IsRequired()
			.OnDelete(DeleteBehavior.NoAction);
		_ = builder
			.Property(x => x.TemplateId)
			.IsRequired()
			.HasConversion(x => x.Value, x => new(x));

		_ = builder
			.HasOne(x => x.AlarmScope)
			.WithMany(x => x.CheckLists)
			.HasForeignKey(x => x.AlarmScopeId)
			.IsRequired()
			.OnDelete(DeleteBehavior.NoAction);
		_ = builder
			.Property(x => x.AlarmScopeId)
			.IsRequired()
			.HasConversion(x => x.Value, x => new(x));
	}
}
