package types

import "apps/backend/internal/module/usage/domain"

func UsageSummaryFromDomain(s *domain.MonthSummary) *UsageSummaryData {
	if s == nil {
		return nil
	}
	platBy := map[string]UsageMeterCount{}
	for k, v := range s.Platform.ByMeter {
		platBy[k] = UsageMeterCount{Count: v.Count, Credits: v.Credits}
	}
	byokBy := map[string]UsageMeterCount{}
	for k, v := range s.Byok.ByMeter {
		byokBy[k] = UsageMeterCount{Count: v.Count, Credits: v.Credits}
	}
	return &UsageSummaryData{
		MonthKey: s.MonthKey, Uid: s.UID, PlanId: s.PlanID, Unlimited: s.Unlimited,
		Platform: UsagePlatformBlock{
			CreditsUsed: s.Platform.CreditsUsed, CreditsRemaining: s.Platform.CreditsRemaining,
			CreditsTotal: s.Platform.CreditsTotal, CallCount: s.Platform.CallCount, ByMeter: platBy,
		},
		Byok: UsageByokBlock{CallCount: s.Byok.CallCount, ByMeter: byokBy},
		TotalCredits: s.TotalCredits, RemainingCredits: s.RemainingCredits,
	}
}

func UsageEventFromDomain(e *domain.Event) UsageEventPublic {
	return UsageEventPublic{
		Id: e.ID, Uid: e.UID, Meter: e.Meter, Credits: e.Credits, KeyMode: e.KeyMode,
		Label: e.Label, Source: e.Source, CreatedAt: e.CreatedAt,
	}
}
