package dto

import (
	"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
)

// NewListActiveAlarmResponse 从模型数据创建活跃告警列表响应 DTO
func NewListActiveAlarmResponse(data []models.ActiveAlarm, total int64, page, pageSize int) *ListActiveAlarmResponse {
	dtos := make([]ActiveAlarmDTO, len(data))
	for i, item := range data {
		dtos[i] = ActiveAlarmDTO{
			ID:             item.ID,
			CreatedAt:      item.CreatedAt,
			UpdatedAt:      item.UpdatedAt,
			SourceType:     item.SourceType,
			SourceID:       item.SourceID,
			AlarmCode:      item.AlarmCode,
			AlarmSummary:   item.AlarmSummary,
			Level:          item.Level,
			AlarmDetails:   item.AlarmDetails,
			TriggerTime:    item.TriggerTime,
			IsIgnored:      item.IsIgnored,
			IgnoredUntil:   item.IgnoredUntil,
			LastNotifiedAt: item.LastNotifiedAt,
		}
	}

	return &ListActiveAlarmResponse{
		List: dtos,
		Pagination: PaginationDTO{
			Total:    total,
			Page:     page,
			PageSize: pageSize,
		},
	}
}

// NewListHistoricalAlarmResponse 从模型数据创建历史告警列表响应 DTO
func NewListHistoricalAlarmResponse(data []models.HistoricalAlarm, total int64, page, pageSize int) *ListHistoricalAlarmResponse {
	dtos := make([]HistoricalAlarmDTO, len(data))
	for i, item := range data {
		dtos[i] = HistoricalAlarmDTO{
			ID:            item.ID,
			SourceType:    item.SourceType,
			SourceID:      item.SourceID,
			AlarmCode:     item.AlarmCode,
			AlarmSummary:  item.AlarmSummary,
			Level:         item.Level,
			AlarmDetails:  item.AlarmDetails,
			TriggerTime:   item.TriggerTime,
			ResolveTime:   item.ResolveTime,
			ResolveMethod: item.ResolveMethod,
			ResolvedBy:    item.ResolvedBy,
		}
	}

	return &ListHistoricalAlarmResponse{
		List: dtos,
		Pagination: PaginationDTO{
			Total:    total,
			Page:     page,
			PageSize: pageSize,
		},
	}
}
