import { expect, describe, it } from 'vitest';
import type { QueryMultiGraph } from 'ts-common/src/model/graphology';
import { MLTypesEnum } from 'ts-common/src/model/query/machineLearningModel';
import { type QueryBuilderSettings } from 'ts-common/src/model/query/queryBuilderModel';
import { Query2BackendQuery } from './../../../utils/reactflow/query2backend';
import type { MachineLearning } from 'ts-common/src/model/query/queryRequestModel';
import { type BackendQueryFormat } from 'ts-common';
import { createQueryMultiGraphFromData, settingsBase, ss_id } from './testData';
import { visualQuery_1 } from './testData';
import { expectedResult_1 } from './testData';
import { Logger } from 'ts-common';

Logger.excludedOwners.push('ts-common');

describe('query2backend', () => {
  it('should return correctly a node - 0', () => {
    const nodesData = [
      {
        id: 'Movie',
        schemaKey: 'Movie',
        type: 'entity',
        width: 100,
        height: 100,
        x: 50,
        y: 50,
        name: 'Movie',
        attributes: [
          { name: '(# Connection)', type: 'float' },
          { name: 'tagline', type: 'string' },
          { name: 'votes', type: 'int' },
          { name: 'title', type: 'string' },
          { name: 'released', type: 'int' },
        ],
      },
    ];

    const visualQuery: QueryMultiGraph = createQueryMultiGraphFromData(nodesData, []);

    const ml: MachineLearning[] = [
      { type: MLTypesEnum.linkPrediction, parameters: [], id: 1 },
      { type: MLTypesEnum.centrality, parameters: [], id: 2 },
      { type: MLTypesEnum.communityDetection, parameters: [], id: 3 },
      { type: MLTypesEnum.shortestPath, parameters: [], id: 4 },
    ];

    const result = Query2BackendQuery(ss_id, visualQuery, settingsBase, ml);
    const expectedResult: BackendQueryFormat = {
      saveStateID: 'test',
      query: [
        {
          id: 'path_0',
          node: {
            label: 'Movie',
            id: 'Movie',
            relation: undefined,
          },
        },
      ],
      machineLearning: [
        { type: MLTypesEnum.linkPrediction, parameters: [], id: 1 },
        { type: MLTypesEnum.centrality, parameters: [], id: 2 },
        { type: MLTypesEnum.communityDetection, parameters: [], id: 3 },
        { type: MLTypesEnum.shortestPath, parameters: [], id: 4 },
      ],
      limit: 500,
      return: ['*'],
      cached: false,
      logic: undefined,
    };
    expect(result).toEqual(expectedResult);
  });
  it('should return correctly on a simple query with multiple paths - 1', () => {
    const ml: MachineLearning[] = [
      { type: MLTypesEnum.linkPrediction, parameters: [], id: 1 },
      { type: MLTypesEnum.centrality, parameters: [], id: 2 },
      { type: MLTypesEnum.communityDetection, parameters: [], id: 3 },
      { type: MLTypesEnum.shortestPath, parameters: [], id: 4 },
    ];

    const result = Query2BackendQuery(ss_id, visualQuery_1, settingsBase, ml);

    expect(result).toEqual(expectedResult_1);
  });
  /*
  it('should return correctly on a complex query with logic', () => {});
  it('should return correctly on a query with group by logic', () => {});
  it('should return correctly on a query with no label', () => {});
  it('should return correctly on a query with no depth', () => {});
  it('should return correctly on a query with average calculation', () => {});
  it('should return correctly on a query with average calculation and multiple paths', () => {});
  it('should return correctly on a single entity query with lower like logic', () => {});
  it('should return correctly on a query with like logic', () => {});
  it('should return correctly on a query with both direction relation', () => {});
*/
});