package repoimpl

import (
	"time"
	"voucher/internal/pkg/mapstructure"
)

type Base[D any, B any] struct{}

func (*Base[D, B]) ToBo(d *D) *B {
	if d == nil {
		return nil
	}

	var b *B
	_ = mapstructure.DecodeWithTime(d, &b, time.DateTime)

	return b
}

func (base *Base[D, B]) ToBos(ds []*D) []*B {
	if ds == nil {
		return nil
	}

	bos := make([]*B, len(ds))

	for k, p := range ds {
		bos[k] = base.ToBo(p)
	}

	return bos
}
