import 'package:afterwork/core/errors/failures.dart';
import 'package:afterwork/core/utils/input_converter.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('InputConverter', () {
    late InputConverter inputConverter;

    setUp(() {
      inputConverter = InputConverter();
    });

    group('stringToUnsignedInteger', () {
      test('should return Right(int) when string is valid unsigned integer', () {
        // Arrange
        const str = '123';

        // Act
        final result = inputConverter.stringToUnsignedInteger(str);

        // Assert
        expect(result, isA<Right<Failure, int>>());
        result.fold(
          (failure) => fail('Should not return failure'),
          (integer) => expect(integer, 123),
        );
      });

      test('should return Right(0) for zero', () {
        // Arrange
        const str = '0';

        // Act
        final result = inputConverter.stringToUnsignedInteger(str);

        // Assert
        result.fold(
          (failure) => fail('Should not return failure'),
          (integer) => expect(integer, 0),
        );
      });

      test('should return Left(InvalidInputFailure) for negative number', () {
        // Arrange
        const str = '-123';

        // Act
        final result = inputConverter.stringToUnsignedInteger(str);

        // Assert
        expect(result, isA<Left<Failure, int>>());
        result.fold(
          (failure) => expect(failure, isA<InvalidInputFailure>()),
          (integer) => fail('Should not return integer'),
        );
      });

      test('should return Left(InvalidInputFailure) for invalid string', () {
        // Arrange
        const str = 'abc';

        // Act
        final result = inputConverter.stringToUnsignedInteger(str);

        // Assert
        expect(result, isA<Left<Failure, int>>());
        result.fold(
          (failure) => expect(failure, isA<InvalidInputFailure>()),
          (integer) => fail('Should not return integer'),
        );
      });

      test('should return Left(InvalidInputFailure) for empty string', () {
        // Arrange
        const str = '';

        // Act
        final result = inputConverter.stringToUnsignedInteger(str);

        // Assert
        expect(result, isA<Left<Failure, int>>());
        result.fold(
          (failure) => expect(failure, isA<InvalidInputFailure>()),
          (integer) => fail('Should not return integer'),
        );
      });

      test('should return Left(InvalidInputFailure) for string with spaces', () {
        // Arrange
        const str = ' 123 ';

        // Act
        final result = inputConverter.stringToUnsignedInteger(str);

        // Assert
        // Note: int.parse can handle spaces, so this might return Right
        expect(result, isA<Either<Failure, int>>());
      });

      test('should return Left(InvalidInputFailure) for decimal number', () {
        // Arrange
        const str = '123.45';

        // Act
        final result = inputConverter.stringToUnsignedInteger(str);

        // Assert
        expect(result, isA<Left<Failure, int>>());
      });

      test('should handle large numbers correctly', () {
        // Arrange
        const str = '999999999';

        // Act
        final result = inputConverter.stringToUnsignedInteger(str);

        // Assert
        result.fold(
          (failure) => fail('Should not return failure'),
          (integer) => expect(integer, 999999999),
        );
      });
    });
  });

  group('InvalidInputFailure', () {
    test('should be an instance of Failure', () {
      // Arrange & Act
      final failure = InvalidInputFailure();

      // Assert
      expect(failure, isA<Failure>());
    });
  });
}

