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

using Monitoring.Core.Domain;
using Monitoring.Core.Domain.RolePrimitives;

namespace Monitoring.Infrastructure.Data.Configurations;

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

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

		_ = builder.Property(x => x.UpperCaseName)
			.IsRequired()
			.HasMaxLength(RoleUpperCaseName.MaxLength)
			.HasConversion(x => x.Value, x => RoleUpperCaseName.Create(x));

		_ = builder.HasData([
			Role.Create(
				new(new Guid("60782519-2571-4153-9010-312463165300")),
				RoleName.Create("Administrator")),
			Role.Create(
				new(new Guid("06E83F0A-28F4-470E-BE61-B732029406DB")),
				RoleName.Create("Manager")),
			Role.Create(
				new(new Guid("23B97497-89FA-4778-BBFE-692B5A82EAEC")),
				RoleName.Create("Watcher")),
			Role.Create(
				new(new Guid("6E7C3D9F-7D6A-4D0C-8C9B-7C0D0E8F9F8F")),
				RoleName.Create("Visitor")),
		]);
	}
}
