package mixrepoimpl

import (
	"context"
	"voucher/internal/biz/mixrepos"
	"voucher/internal/conf"
	"voucher/internal/pkg/sms"
)

type SmsMixRepoImpl struct {
	smsService sms.Service
}

func NewSmsMixRepoImpl(bc *conf.Bootstrap) (mixrepos.SmsMixRepo, error) {

	config := sms.Config{
		AccessKeyID:     bc.AliYunSms.AccessKeyId,
		AccessKeySecret: bc.AliYunSms.AccessKeySecret,
		Endpoint:        bc.AliYunSms.Endpoint,
		SignName:        bc.AliYunSms.SignName,
		RetryTimes:      1,
		Timeout:         15,
	}

	smsService, err := sms.NewService(config)
	if err != nil {
		return nil, err
	}

	return &SmsMixRepoImpl{smsService: smsService}, nil
}

func (s *SmsMixRepoImpl) Send(ctx context.Context, phoneNumbers []string, templateCode string, params map[string]string) error {
	return s.smsService.SendSMS(ctx, phoneNumbers, templateCode, params)
}
