/* eslint-disable @typescript-eslint/ban-ts-comment */
import { assert } from '@open-wc/testing';
import { AmfEventTypes } from  '../../../src/index.js';
import { ensureUnique } from './EventHelper.js';

describe('ApiEventTypes', () => {
  describe('Api', () => {
    it('has Api namespace', () => {
      assert.typeOf(AmfEventTypes.Api, 'object');
    });

    it('is frozen', () => {
      assert.throws(() => {
        // @ts-ignore
        AmfEventTypes.Api = { read: '' };
      });
    });

    [
      ['summary', 'amfstoreapisummary'],
    ].forEach(([prop, value]) => {
      it(`has ${prop} property`, () => {
        assert.equal(AmfEventTypes.Api[prop], value);
      });
    });

    it('has unique events for the namespace', () => {
      ensureUnique('AmfEventTypes.Api', AmfEventTypes.Api);
    });
  });

  describe('Endpoint', () => {
    it('has Endpoint namespace', () => {
      assert.typeOf(AmfEventTypes.Endpoint, 'object');
    });

    it('is frozen', () => {
      assert.throws(() => {
        // @ts-ignore
        AmfEventTypes.Endpoint = { read: '' };
      });
    });

    [
      ['get', 'amfstoreendpointget'],
      ['byPath', 'amfstoreendpointbypath'],
      ['list', 'amfstoreendpointlist'],
    ].forEach(([prop, value]) => {
      it(`has ${prop} property`, () => {
        assert.equal(AmfEventTypes.Endpoint[prop], value);
      });
    });

    it('has unique events for the namespace', () => {
      ensureUnique('AmfEventTypes.Endpoint', AmfEventTypes.Endpoint);
    });
  });

  describe('Navigation', () => {
    it('has Navigation namespace', () => {
      assert.typeOf(AmfEventTypes.Navigation, 'object');
    });

    it('is frozen', () => {
      assert.throws(() => {
        // @ts-ignore
        AmfEventTypes.Navigation = { read: '' };
      });
    });

    [
      ['apiNavigate', 'apinavigate'],
    ].forEach(([prop, value]) => {
      it(`has ${prop} property`, () => {
        assert.equal(AmfEventTypes.Navigation[prop], value);
      });
    });

    it('has unique events for the namespace', () => {
      ensureUnique('AmfEventTypes.Navigation', AmfEventTypes.Navigation);
    });
  });

  describe('Server', () => {
    it('has Server namespace', () => {
      assert.typeOf(AmfEventTypes.Server, 'object');
    });

    it('is frozen', () => {
      assert.throws(() => {
        // @ts-ignore
        AmfEventTypes.Server = { read: '' };
      });
    });

    [
      ['serverChange', 'apiserverchanged'],
      ['serverCountChange', 'serverscountchanged'],
    ].forEach(([prop, value]) => {
      it(`has ${prop} property`, () => {
        assert.equal(AmfEventTypes.Server[prop], value);
      });
    });

    it('has unique events for the namespace', () => {
      ensureUnique('AmfEventTypes.Server', AmfEventTypes.Server);
    });
  });

  describe('Security', () => {
    it('has Security namespace', () => {
      assert.typeOf(AmfEventTypes.Security, 'object');
    });

    it('is frozen', () => {
      assert.throws(() => {
        // @ts-ignore
        AmfEventTypes.Security = { read: '' };
      });
    });

    [
      ['settingsChanged', 'securitysettingsinfochanged'],
    ].forEach(([prop, value]) => {
      it(`has ${prop} property`, () => {
        assert.equal(AmfEventTypes.Security[prop], value);
      });
    });

    it('has unique events for the namespace', () => {
      ensureUnique('AmfEventTypes.Security', AmfEventTypes.Security);
    });
  });

  describe('Request', () => {
    it('has Request namespace', () => {
      assert.typeOf(AmfEventTypes.Request, 'object');
    });

    it('is frozen', () => {
      assert.throws(() => {
        // @ts-ignore
        AmfEventTypes.Request = { read: '' };
      });
    });

    [
      ['redirectUriChange', 'oauth2redirecturichange'],
      ['populateAnnotatedFields', 'populateannotatedfields'],
    ].forEach(([prop, value]) => {
      it(`has ${prop} property`, () => {
        assert.equal(AmfEventTypes.Request[prop], value);
      });
    });

    it('has unique events for the namespace', () => {
      ensureUnique('AmfEventTypes.Request', AmfEventTypes.Request);
    });
  });

  describe('Reporting', () => {
    it('has Reporting namespace', () => {
      assert.typeOf(AmfEventTypes.Reporting, 'object');
    });

    it('is frozen', () => {
      assert.throws(() => {
        // @ts-ignore
        AmfEventTypes.Reporting = { read: '' };
      });
    });

    [
      ['error', 'apierror'],
    ].forEach(([prop, value]) => {
      it(`has ${prop} property`, () => {
        assert.equal(AmfEventTypes.Reporting[prop], value);
      });
    });

    it('has unique events for the namespace', () => {
      ensureUnique('AmfEventTypes.Reporting', AmfEventTypes.Reporting);
    });
  });

  describe('Telemetry', () => {
    it('has Telemetry namespace', () => {
      assert.typeOf(AmfEventTypes.Telemetry, 'object');
    });

    it('is frozen', () => {
      assert.throws(() => {
        // @ts-ignore
        AmfEventTypes.Telemetry = { read: '' };
      });
    });

    [
      ['view', 'telemetryscreenview'],
      ['event', 'telemetryevent'],
      ['exception', 'telemetryexception'],
      ['social', 'telemetrysocial'],
      ['timing', 'telemetrytiming'],
    ].forEach(([prop, value]) => {
      it(`has ${prop} property`, () => {
        assert.equal(AmfEventTypes.Telemetry[prop], value);
      });
    });

    it('has unique events for the namespace', () => {
      ensureUnique('AmfEventTypes.Telemetry', AmfEventTypes.Telemetry);
    });
  });

  describe('Store', () => {
    it('has Store namespace', () => {
      assert.typeOf(AmfEventTypes.Store, 'object');
    });

    it('is frozen', () => {
      assert.throws(() => {
        // @ts-ignore
        AmfEventTypes.Store = { read: '' };
      });
    });

    [
      ['graphChange', 'apistoregraphchange'],
    ].forEach(([prop, value]) => {
      it(`has ${prop} property`, () => {
        assert.equal(AmfEventTypes.Store[prop], value);
      });
    });

    it('has unique events for the namespace', () => {
      ensureUnique('AmfEventTypes.Store', AmfEventTypes.Store);
    });
  });
});
