using ControlCenter.Models; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace ControlCenter.Data.Configurations; /// /// EF Core entity configuration for . /// /// Maps to the agents table with snake_case column naming, /// consistent with the Extrudex project conventions. /// /// CUB-56 will create the migration; this configuration only /// defines the entity-to-table mapping and constraints. /// public class AgentStateConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { // Table name builder.ToTable("agents"); // Primary key builder.HasKey(a => a.Id); // Properties with snake_case column names builder.Property(a => a.Id) .HasColumnName("id") .ValueGeneratedOnAdd(); builder.Property(a => a.Status) .HasColumnName("status") .IsRequired() .HasMaxLength(20) .HasDefaultValue("idle"); builder.Property(a => a.Task) .HasColumnName("task") .IsRequired(false) .HasMaxLength(500); builder.Property(a => a.Progress) .HasColumnName("progress") .IsRequired(false); builder.Property(a => a.SessionKey) .HasColumnName("session_key") .IsRequired() .HasMaxLength(255); builder.Property(a => a.Channel) .HasColumnName("channel") .IsRequired() .HasMaxLength(50); builder.Property(a => a.LastActivity) .HasColumnName("last_activity") .IsRequired() .HasDefaultValueSql("NOW()"); // Indexes builder.HasIndex(a => a.SessionKey) .IsUnique() .HasDatabaseName("ix_agents_session_key"); builder.HasIndex(a => a.Status) .HasDatabaseName("ix_agents_status"); } }