import { ReturnValue } from './return-value';

describe('ReturnValue', () => {
  describe('interface structure', () => {
    it('should support all properties', () => {
      // Arrange
      const testData: ReturnValue<string> = {
        error: false,
        invalidProperties: { field1: 'Invalid value', field2: 'Another error' },
        message: 'Operation successful',
        result: 'test result',
      };

      // Assert
      expect(testData.error).toBe(false);
      expect(testData.invalidProperties).toEqual({ 
        field1: 'Invalid value', 
        field2: 'Another error' 
      });
      expect(testData.message).toBe('Operation successful');
      expect(testData.result).toBe('test result');
    });

    it('should support required properties only', () => {
      // Arrange
      const testData: ReturnValue<number> = {
        error: true,
        result: 42,
      };

      // Assert
      expect(testData.error).toBe(true);
      expect(testData.result).toBe(42);
      expect(testData.invalidProperties).toBeUndefined();
      expect(testData.message).toBeUndefined();
    });

    it('should support generic type parameter', () => {
      // Arrange
      interface TestObject {
        id: number;
        name: string;
      }

      const testObject: TestObject = { id: 1, name: 'test' };
      const testData: ReturnValue<TestObject> = {
        error: false,
        result: testObject,
      };

      // Assert
      expect(testData.result.id).toBe(1);
      expect(testData.result.name).toBe('test');
    });

    it('should support arrays as generic type', () => {
      // Arrange
      const testData: ReturnValue<string[]> = {
        error: false,
        result: ['item1', 'item2', 'item3'],
        message: 'Array operation successful',
      };

      // Assert
      expect(testData.result).toHaveLength(3);
      expect(testData.result[0]).toBe('item1');
      expect(testData.result[1]).toBe('item2');
      expect(testData.result[2]).toBe('item3');
    });

    it('should support null result', () => {
      // Arrange
      const testData: ReturnValue<string | null> = {
        error: false,
        result: null,
      };

      // Assert
      expect(testData.result).toBeNull();
    });

    it('should support error state with message', () => {
      // Arrange
      const testData: ReturnValue<string> = {
        error: true,
        message: 'Operation failed',
        result: '',
      };

      // Assert
      expect(testData.error).toBe(true);
      expect(testData.message).toBe('Operation failed');
      expect(testData.result).toBe('');
    });

    it('should support complex invalidProperties', () => {
      // Arrange
      const testData: ReturnValue<any> = {
        error: true,
        invalidProperties: {
          'user.email': 'Invalid email format',
          'user.age': 'Age must be a positive number',
          'nested.field.value': 'Required field missing',
        },
        result: null,
      };

      // Assert
      expect(testData.invalidProperties).toEqual({
        'user.email': 'Invalid email format',
        'user.age': 'Age must be a positive number',
        'nested.field.value': 'Required field missing',
      });
    });

    it('should support empty invalidProperties', () => {
      // Arrange
      const testData: ReturnValue<string> = {
        error: false,
        invalidProperties: {},
        result: 'success',
      };

      // Assert
      expect(testData.invalidProperties).toEqual({});
    });
  });
});