package user

import (
	"context"
	"fmt"
)

func (s *service) CentsToPoints(ctx context.Context, cents int64) (int64, error) {
	if cents <= 0 {
		return 0, nil
	}
	cfg, _ := s.readDB.SystemConfigs.WithContext(ctx).Where(s.readDB.SystemConfigs.ConfigKey.Eq("points_exchange_per_cent")).First()
	rate := int64(1)
	if cfg != nil {
		var r int64
		_, _ = fmt.Sscanf(cfg.ConfigValue, "%d", &r)
		if r > 0 {
			rate = r
		}
	}
	return cents * rate, nil
}
