package service

import (
	"context"
	"time"

	"kra/internal/biz"
)

type SecurityService struct {
	uc *biz.SecurityUsecase
}

func NewSecurityService(uc *biz.SecurityUsecase) *SecurityService {
	return &SecurityService{uc: uc}
}

func (s *SecurityService) ActiveToken(ctx context.Context, username string) (string, error) {
	return s.uc.ActiveToken(ctx, username)
}

func (s *SecurityService) LoginLocked(ctx context.Context, username string) (bool, error) {
	return s.uc.LoginLocked(ctx, username)
}

func (s *SecurityService) IncrementLoginFailure(ctx context.Context, username string, expiration time.Duration) (int64, error) {
	return s.uc.IncrementLoginFailure(ctx, username, expiration)
}

func (s *SecurityService) LockLogin(ctx context.Context, username string, expiration time.Duration) error {
	return s.uc.LockLogin(ctx, username, expiration)
}

func (s *SecurityService) ClearLoginState(ctx context.Context, username string) {
	s.uc.ClearLoginState(ctx, username)
}

func (s *SecurityService) EnsureLoginIPCounter(ctx context.Context, ip string, expiration time.Duration) (int, error) {
	return s.uc.EnsureLoginIPCounter(ctx, ip, expiration)
}

func (s *SecurityService) IncrementLoginIP(ctx context.Context, ip string, expiration time.Duration) (int64, error) {
	return s.uc.IncrementLoginIP(ctx, ip, expiration)
}

func (s *SecurityService) IncrementRateLimit(ctx context.Context, key string, expiration time.Duration) (int64, error) {
	return s.uc.IncrementRateLimit(ctx, key, expiration)
}

func (s *SecurityService) SetCaptcha(ctx context.Context, id, value string, expiration time.Duration) error {
	return s.uc.SetCaptcha(ctx, id, value, expiration)
}

func (s *SecurityService) GetCaptcha(ctx context.Context, id string) (string, bool, error) {
	return s.uc.GetCaptcha(ctx, id)
}

func (s *SecurityService) DeleteCaptcha(ctx context.Context, id string) error {
	return s.uc.DeleteCaptcha(ctx, id)
}

func (s *SecurityService) UseMultipoint() bool { return s.uc.UseMultipoint() }

func (s *SecurityService) CaptchaSettings() biz.CaptchaSettings {
	return s.uc.CaptchaRuntimeSettings()
}

func (s *SecurityService) ActiveTokenMatches(ctx context.Context, username, token string) (bool, error) {
	return s.uc.ActiveTokenMatches(ctx, username, token)
}

func (s *SecurityService) RotateActiveToken(ctx context.Context, username, oldToken, newToken string, expiration time.Duration) error {
	return s.uc.RotateActiveToken(ctx, username, oldToken, newToken, expiration)
}
