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

namespace MiGu.DB.Domains.Fleet;

public sealed class CdmTaskRecordConfiguration : IEntityTypeConfiguration<CdmTaskRecord>
{
    public void Configure(EntityTypeBuilder<CdmTaskRecord> e)
    {
        e.ToTable("cdm_tasks");
        e.HasKey(x => x.Id);
        e.Property(x => x.Id).HasColumnName("id").HasMaxLength(64);
        e.Property(x => x.TaskId).HasColumnName("task_id").HasMaxLength(128).IsRequired(false);
        e.Property(x => x.MissionId).HasColumnName("mission_id");
        e.Property(x => x.MissionName).HasColumnName("mission_name").HasMaxLength(128);
        e.Property(x => x.MissionTypeName).HasColumnName("mission_type").HasMaxLength(128);
        e.Property(x => x.SrcSiteId).HasColumnName("src_site_id");
        e.Property(x => x.SrcLabel).HasColumnName("src_label").HasMaxLength(256);
        e.Property(x => x.DstSiteId).HasColumnName("dst_site_id");
        e.Property(x => x.DstLabel).HasColumnName("dst_label").HasMaxLength(256);
        e.Property(x => x.Status).HasColumnName("status").HasMaxLength(32);
        e.Property(x => x.StatusCode).HasColumnName("status_code").HasMaxLength(32);
        e.Property(x => x.CarId).HasColumnName("car_id").IsRequired(false);
        e.Property(x => x.CarName).HasColumnName("car_name").HasMaxLength(128).IsRequired(false);
        e.Property(x => x.Priority).HasColumnName("priority");
        e.Property(x => x.CreateTime).HasColumnName("create_time").HasMaxLength(40).IsRequired(false);
        e.Property(x => x.StartTime).HasColumnName("start_time").HasMaxLength(40).IsRequired(false);
        e.Property(x => x.FinishTime).HasColumnName("finish_time").HasMaxLength(40).IsRequired(false);
        e.Property(x => x.StuckReason).HasColumnName("stuck_reason").HasMaxLength(512).IsRequired(false);
        e.Property(x => x.Overdue).HasColumnName("overdue");
        e.Property(x => x.FirstSeenAt).HasColumnName("first_seen_at");
        e.Property(x => x.LastSeenAt).HasColumnName("last_seen_at");
        e.HasIndex(x => x.StatusCode);
        e.HasIndex(x => x.CreateTime);
    }
}

public sealed class VehicleAlarmRecordConfiguration : IEntityTypeConfiguration<VehicleAlarmRecord>
{
    public void Configure(EntityTypeBuilder<VehicleAlarmRecord> e)
    {
        e.ToTable("vehicle_alarms");
        e.HasKey(x => x.Id);
        e.Property(x => x.Id).HasColumnName("id").HasMaxLength(36);
        e.Property(x => x.CarId).HasColumnName("car_id");
        e.Property(x => x.CarName).HasColumnName("car_name").HasMaxLength(128);
        e.Property(x => x.Info).HasColumnName("info").HasColumnType("text");
        e.Property(x => x.Level).HasColumnName("level");
        e.Property(x => x.Status).HasColumnName("status").HasMaxLength(16);
        e.Property(x => x.FirstAt).HasColumnName("first_at");
        e.Property(x => x.LastAt).HasColumnName("last_at");
        e.Property(x => x.ResolvedAt).HasColumnName("resolved_at").IsRequired(false);
        e.Property(x => x.DurationSecs).HasColumnName("duration_secs").IsRequired(false);
        e.Property(x => x.Acknowledged).HasColumnName("acknowledged");
        e.Property(x => x.AcknowledgedAt).HasColumnName("acknowledged_at").IsRequired(false);
        e.Property(x => x.AcknowledgedBy).HasColumnName("acknowledged_by").HasMaxLength(128).IsRequired(false);
        e.HasIndex(x => new { x.CarId, x.Status });
        e.HasIndex(x => x.Status);
        e.HasIndex(x => x.FirstAt);
    }
}
