package redisotp

import (
	"context"

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

func (d DB) IsExistPhoneNumber(ctx context.Context, phoneNumber string) (bool, error) {
	const op = "redisotp.IsExistPhoneNumber"

	isExist, err := d.adapter.Client().Exists(ctx, phoneNumber).Result()
	if err != nil {
		return false, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
	}
	if isExist == 0 {
		return false, nil
	}

	return true, nil
}