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

namespace Monitoring.Infrastructure.Data.Configurations;

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

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

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