package adminrefertimeaggregatorservice

import (
	"context"

	param "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
	richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)

func (s Service) GetReferTimeByIDs(ctx context.Context, ids []any) (map[uint]param.Data, error) {
	const op = "adminrefertimeaggregatorservice.GetReferTimeByIDs"
	data := make(map[uint]param.Data)

	referTimes, err := s.repo.GetByIDs(ctx, ids)
	if err != nil {
		return nil, richerror.New(op).WithErr(err)
	}
	for _, referTime := range referTimes {
		data[referTime.ID] = param.Data{
			ID:       referTime.ID,
			Status:   referTime.Status,
			Duration: referTime.Duration,
		}
	}
	return data, nil
}

func (s Service) GetReferTimeByID(ctx context.Context, id uint) (param.Data, error) {
	const op = "adminrefertimeaggregatorservice.GetReferTimeByID"
	referTime, gErr := s.repo.Get(ctx, id)
	if gErr != nil {
		return param.Data{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
	}

	return param.Data{
		ID:       referTime.ID,
		Status:   referTime.Status,
		Duration: referTime.Duration,
	}, nil
}
