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

namespace GeoRitmMover.Mover.Data.EntityConfigurations;
public class AccessMapEntityConfiguration : IEntityTypeConfiguration<AccessMap>
{
	public void Configure(EntityTypeBuilder<AccessMap> builder)
	{
		_ = builder.HasKey(x => x.Id);

		_ = builder.ComplexProperty(x => x.From, builder =>
		{
			_ = builder.Property(x => x.UserId)
				.IsRequired();
			_ = builder.Property(x => x.InventoryId)
				.IsRequired();
		});

		_ = builder.Property(x => x.To)
			.IsRequired()
			.HasConversion(x => x.Value, x => new(x));
		_ = builder.HasIndex(x => x.To).IsUnique();
	}
}
