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

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

namespace Monitoring.Infrastructure.Data.Configurations;

public class AlarmResetCommentTranslateConfiguration  : IEntityTypeConfiguration<AlarmResetCommentTranslate>
{
	public void Configure(EntityTypeBuilder<AlarmResetCommentTranslate> builder)
	{
		_ = builder.HasKey(x => x.Id);
		_ = builder.Property(x => x.Id)
			.IsRequired()
			.HasConversion( id => id.Value, value => new AlarmResetCommentTranslateId(value));
		
		_ = builder.Property(x => x.Value)
			.IsRequired()
			.HasConversion( x => x.Value, value => AlarmResetCommentValue.Create(value));
		
		_ = builder.Property(x => x.Language)
			.IsRequired()
			.HasConversion( x => x.Value, language => AlarmResetCommentLanguage.Create(language));

		_ = builder.HasOne(x => x.Comment)
			.WithMany(x => x.Translates)
			.HasForeignKey(x=>x.CommentId)
			.IsRequired()
			.OnDelete(DeleteBehavior.Cascade);
	}
}