using Microsoft.EntityFrameworkCore;

using Monitoring.Core.Domain.OrganizationManagement;

namespace Monitoring.Infrastructure.Data.Configurations;

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

		_ = builder.Property(x => x.Name)
			.HasMaxLength(OrganizationName.MaxLength)
			.IsRequired()
			.HasConversion(x => x.Value, x => OrganizationName.Create(x));
		_ = builder.HasIndex(x => x.Name)
			.IsUnique();

		_ = builder.Property(x => x.Description)
			.HasMaxLength(OrganizationDescription.MaxLength)
			.IsRequired()
			.HasConversion(x => x.Value, x => OrganizationDescription.Create(x));
	}
}
