import { serializeReturnDetails, returnDetailsMapping } from './return-details-mapping.helper';

// Mock ReturnProcessQuestionKey for testing purposes
enum MockReturnProcessQuestionKey {
    Reason = 'reason',
    Quantity = 'quantity',
    Comments = 'comments',
    Tags = 'tags',
}

describe('serializeReturnDetails', () => {
    it('should return undefined for undefined input', () => {
        // Arrange
        const input = undefined;

        // Act
        const result = serializeReturnDetails(input as any);

        // Assert
        expect(result).toBeUndefined();
    });

    it('should return undefined for empty object', () => {
        // Arrange
        const input = {};

        // Act
        const result = serializeReturnDetails(input as any);

        // Assert
        expect(result).toBeUndefined();
    });

    it('should serialize single key-value pair', () => {
        // Arrange
        const input = { [MockReturnProcessQuestionKey.Reason]: 'Damaged' };

        // Act
        const result = serializeReturnDetails(input as any);

        // Assert
        expect(result).toBe('reason:Damaged');
    });

    it('should serialize multiple key-value pairs', () => {
        // Arrange
        const input = {
            [MockReturnProcessQuestionKey.Reason]: 'Wrong Size',
            [MockReturnProcessQuestionKey.Quantity]: 2,
        };

        // Act
        const result = serializeReturnDetails(input as any);

        // Assert
        expect(result).toBe('reason:Wrong Size;quantity:2');
    });

    it('should serialize values of different types', () => {
        // Arrange
        const input = {
            [MockReturnProcessQuestionKey.Quantity]: 5,
            [MockReturnProcessQuestionKey.Comments]: null,
            [MockReturnProcessQuestionKey.Tags]: ['urgent', 123],
        };

        // Act
        const result = serializeReturnDetails(input as any);

        // Assert
        expect(result).toBe('quantity:5;comments:null;tags:urgent,123');
    });
});

describe('returnDetailsMapping', () => {
    it('should return empty array for empty object', () => {
        // Arrange
        const input = {};

        // Act
        const result = returnDetailsMapping(input as any);

        // Assert
        expect(result).toEqual([]);
    });

    it('should map single key-value pair', () => {
        // Arrange
        const input = { [MockReturnProcessQuestionKey.Reason]: 'Defective' };

        // Act
        const result = returnDetailsMapping(input as any);

        // Assert
        expect(result).toEqual(['reason: Defective']);
    });

    it('should map multiple key-value pairs', () => {
        // Arrange
        const input = {
            [MockReturnProcessQuestionKey.Reason]: 'Other',
            [MockReturnProcessQuestionKey.Quantity]: 1,
        };

        // Act
        const result = returnDetailsMapping(input as any);

        // Assert
        expect(result).toEqual(['reason: Other', 'quantity: 1']);
    });

    it('should join array values with comma and space', () => {
        // Arrange
        const input = {
            [MockReturnProcessQuestionKey.Tags]: ['fragile', 'return', 42],
        };

        // Act
        const result = returnDetailsMapping(input as any);

        // Assert
        expect(result).toEqual(['tags: fragile, return, 42']);
    });

    it('should handle null and undefined values', () => {
        // Arrange
        const input = {
            [MockReturnProcessQuestionKey.Comments]: null,
            [MockReturnProcessQuestionKey.Quantity]: undefined,
        };

        // Act
        const result = returnDetailsMapping(input as any);

        // Assert
        expect(result).toEqual(['comments: null', 'quantity: undefined']);
    });
});