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

namespace Monitoring.Infrastructure.Data.Configurations;

public class CheckListItemConfiguration : IEntityTypeConfiguration<CheckListItem>
{
	public void Configure(
		Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder<CheckListItem> 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.CheckList)
			.WithMany(x => x.Items)
			.HasForeignKey(x => x.CheckListId)
			.IsRequired()
			.OnDelete(DeleteBehavior.NoAction);
		_ = builder
			.Property(x => x.CheckListId)
			.IsRequired()
			.HasConversion(x => x.Value, x => new(x));

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