package redisotp

import (
	"context"
	"time"

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

func (d DB) SaveCodeWithPhoneNumber(ctx context.Context, phoneNumber, code string, expireTime time.Duration) error {
	const op = "redisotp.SaveCodeWithPhoneNumber"

	err := d.adapter.Client().Set(ctx, phoneNumber, code, expireTime).Err()
	if err != nil {
		return richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
	}

	return nil
}