using AutobusApi.Domain.Entities; using AutobusApi.Domain.Enums; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace AutobusApi.Infrastructure.Data.Configurations; public class TicketDocumentConfiguration : EntityBaseConfiguration { public override void Configure(EntityTypeBuilder builder) { base.Configure(builder); builder .ToTable("ticket_documents") .HasKey(e => e.Id); builder .Property(td => td.Type) .HasColumnName("type") .HasColumnType("varchar(32)") .HasConversion( e => e.ToString(), s => (TicketDocumentType)Enum.Parse(typeof(TicketDocumentType), s) ) .IsRequired(); builder .Property(td => td.Information) .HasColumnName("information") .HasColumnType("varchar(256)") .IsRequired(); builder .Property(td => td.TicketGroupId) .HasColumnName("ticket_group_id") .HasColumnType("int") .IsRequired(); builder .HasOne(td => td.TicketGroup) .WithOne(tg => tg.TicketDocument) .HasForeignKey(td => td.TicketDocumentId) .HasConstraintName("fk_ticketDocuments_ticketGroups_ticketDocumentId") .OnDelete(DeleteBehavior.Cascade); } }