import { renderHook } from '@testing-library/react';
import { BRAND_AWAL, BRAND_KNR, BRAND_SME, BRAND_ORCHARD } from '@theorchard/constants';
import { usePaymentEntityByName } from '../usePaymentEntityByName';

describe('usePaymentEntityByName', () => {
    it('returns all false flags and null values when no entity is detected', () => {
        const { result } = renderHook(() => usePaymentEntityByName('Unknown-Entity'));

        expect(result.current).toEqual({
            entityName: null,
            entityFullName: 'Unknown-Entity',
            isAWAL: false,
            isKNR: false,
            isSME: false,
            isOrchard: false,
            hasEntity: false,
        });
    });

    it.each([
        ['AWAL-UK', BRAND_AWAL, { isAWAL: true }],
        ['KNR-NL', BRAND_KNR, { isKNR: true }],
        ['SME-Core', BRAND_SME, { isSME: true }],
        ['Orchard-ES', BRAND_ORCHARD, { isOrchard: true }],
    ])('correctly detects "%s" as %s', (fullName, expectedBrand, flags) => {
        const { result } = renderHook(() => usePaymentEntityByName(fullName));

        expect(result.current.entityName).toBe(expectedBrand);
        expect(result.current.entityFullName).toBe(fullName);
        expect(result.current.hasEntity).toBe(true);

        Object.entries(flags).forEach(([flag, value]) => {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            expect((result.current as any)[flag]).toBe(value);
        });
    });

    it('handles null entityFullName gracefully', () => {
        const { result } = renderHook(() => usePaymentEntityByName(null));

        expect(result.current).toEqual({
            entityName: null,
            entityFullName: null,
            isAWAL: false,
            isKNR: false,
            isSME: false,
            isOrchard: false,
            hasEntity: false,
        });
    });
});
