using CMSMicroservice.Protobuf.Protos.Health;
using CMSMicroservice.Application.HealthCQ.Queries.GetSystemHealth;
using Google.Protobuf.WellKnownTypes;

namespace CMSMicroservice.WebApi.Common.Mappings;

public class HealthProfile : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        // DTO to Proto mappings
        config.NewConfig<GetSystemHealthResponseDto, GetSystemHealthResponse>()
            .Map(dest => dest.OverallHealthy, src => src.OverallHealthy)
            .Map(dest => dest.Services, src => src.Services)
            .Map(dest => dest.CheckedAt, src => Timestamp.FromDateTime(src.CheckedAt))
            .Map(dest => dest.Version, src => src.Version)
            .Map(dest => dest.Environment, src => src.Environment);

        config.NewConfig<ServiceHealthDto, ServiceHealthModel>()
            .Map(dest => dest.ServiceName, src => src.ServiceName)
            .Map(dest => dest.Status, src => src.Status)
            .Map(dest => dest.Description, src => src.Description)
            .Map(dest => dest.ResponseTimeMs, src => src.ResponseTimeMs)
            .Map(dest => dest.LastCheck, src => Timestamp.FromDateTime(src.LastCheck))
            .Map(dest => dest.Details, src => src.Details);

        config.NewConfig<HealthDetailDto, HealthDetail>()
            .Map(dest => dest.Key, src => src.Key)
            .Map(dest => dest.Value, src => src.Value)
            .Map(dest => dest.Status, src => src.Status);

        // Enum mappings
        config.NewConfig<HealthStatusDto, HealthStatus>()
            .Map(dest => dest, src => (HealthStatus)(int)src);
    }
}