using AutobusApi.Domain.Entities; using AutobusApi.Domain.Enums; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace AutobusApi.Infrastructure.Data.Configurations; public class CarriageConfiguration : EntityBaseConfiguration { public override void Configure(EntityTypeBuilder builder) { base.Configure(builder); builder .ToTable("carriages") .HasKey(e => e.Id); builder .Property(b => b.Type) .HasColumnName("type") .HasColumnType("varchar(16)") .HasConversion( e => e.ToString(), s => (CarriageType)Enum.Parse(typeof(CarriageType), s) ) .IsRequired(); builder .Property(b => b.Capacity) .HasColumnName("capacity") .HasColumnType("int") .IsRequired(); builder .Property(b => b.Number) .HasColumnName("number") .HasColumnType("int") .IsRequired(); builder .Property(b => b.HasWiFi) .HasColumnName("has_wifi") .HasColumnType("boolean") .IsRequired(); builder .Property(b => b.HasOutlets) .HasColumnName("has_outlets") .HasColumnType("boolean") .IsRequired(); builder .HasMany(c => c.TrainCarriage) .WithOne(tc => tc.Carriage) .OnDelete(DeleteBehavior.Cascade); } }