using audit_logs.Models;
using audit.Model;

namespace audit_logs.Utils;

public static class AuditRecordMapper
{
    public static AuditRecordDto ToDto(this AuditRecord record)
    {
        return new AuditRecordDto
        {
            Id = record.Id.ToString(),
            EntityType = record.EntityType,
            RecordId = record.RecordId,
            UserId = record.UserId,
            ActionType = record.ActionType,
            ActionTime = record.ActionTime,
            Reason = record.Reason,
            UserIpAddress = record.UserIpAddress,
            Changes = record.Changes?.Select(c => new ChangeDto
            {
                Field = c.Field,
                OldValue = AuditRecord.Change.ConvertBsonValue(c.OldValue),
                NewValue = AuditRecord.Change.ConvertBsonValue(c.NewValue),
                ValueType = c.ValueType
            }).ToList() ?? new List<ChangeDto>()
        };
    }
}
