using Microsoft.EntityFrameworkCore;

using Monitoring.Core.Domain;
using Monitoring.Core.Domain.AssetManagement;

namespace Monitoring.Infrastructure.Data.Configurations;

public class PhotoConfiguration : IEntityTypeConfiguration<Photo>
{
	public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder<Photo> builder)
	{
		_ = builder.Property(x => x.Name)
			.IsRequired()
			.HasMaxLength(AssetName.MaxLength);

		_ = builder.Property(x => x.Description)
			.IsRequired()
		   .HasMaxLength(AssetDescription.MaxLength);

		_ = builder.Property(x => x.Base64)
			.IsRequired();

		_ = builder.HasOne(x => x.Asset)
			.WithMany(x => x.Photos)
			.HasForeignKey(x => x.AssetId)
			.IsRequired()
			.OnDelete(DeleteBehavior.Cascade);
		_ = builder.Property(x => x.AssetId)
			.HasConversion(x => x.Value, x => new(x));
	}
}
