import 'package:baseproject/features/model/index.dart';
import 'package:baseproject/features/repositories/hra_repository.dart';
import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';

@lazySingleton
class UserUseCases {
  final HraRepository _hraRepository;

  UserUseCases(this._hraRepository);

  Future<Either<String, LoginResponseDto>> loginAccount(LoginDto request) async {
    try {
      final result = await _hraRepository.accountLogin(request);

      if (result.data == null) {
        return Left<String, LoginResponseDto>(result.message ?? 'Login failed');
      }

      return Right<String, LoginResponseDto>(result.data!);
    } catch (ex) {
      return Left<String, LoginResponseDto>(ex.toString());
    }
  }

  Future<Either<String, DNTCaptchaApiResponse>> getCaptcha() async {
    try {
      final result = await _hraRepository.accountCaptcha();

      return Right<String, DNTCaptchaApiResponse>(result);
    } catch (ex) {
      return Left<String, DNTCaptchaApiResponse>(ex.toString());
    }
  }
}
