using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Monitoring.Core.Domain.FireDepartmentManagement;

namespace Monitoring.Infrastructure.Data.Configurations;

public class FireDepartmentConfiguration : IEntityTypeConfiguration<FireDepartment>
{
    public void Configure(EntityTypeBuilder<FireDepartment> builder)
    {
        builder.HasKey(x => x.Id);
        builder.Property(x => x.Id)
            .IsRequired()
            .HasConversion(x => x.Value, x => new(x));

        builder.Property(x => x.Name)
            .IsRequired()
            .HasConversion(x => x.Value, x => FireDepartmentName.Create(x))
            .HasMaxLength(FireDepartmentName.MaxLength);

        builder.Property(x => x.Address)
            .IsRequired()
            .HasConversion(x => x.Value, x => FireDepartmentAddress.Create(x))
            .HasMaxLength(FireDepartmentAddress.MaxLength);
    }
}