import { describe, expect, it } from 'vitest';

import { getDataSourceCapabilities } from './dataSourceCapabilities';

describe('dataSourceCapabilities', () => {
  it('treats Oracle table preview totals as manual exact count plus approximate metadata count', () => {
    expect(getDataSourceCapabilities({ type: 'oracle' })).toMatchObject({
      type: 'oracle',
      preferManualTotalCount: true,
      supportsApproximateTableCount: true,
      supportsApproximateTotalPages: false,
    });
  });

  it('keeps DuckDB manual count and approximate total support', () => {
    expect(getDataSourceCapabilities({ type: 'duckdb' })).toMatchObject({
      type: 'duckdb',
      preferManualTotalCount: true,
      supportsApproximateTableCount: true,
      supportsApproximateTotalPages: true,
    });
  });

  it('keeps MySQL on automatic total count mode', () => {
    expect(getDataSourceCapabilities({ type: 'mysql' })).toMatchObject({
      type: 'mysql',
      preferManualTotalCount: false,
      supportsApproximateTableCount: false,
      supportsApproximateTotalPages: false,
    });
  });

  it('keeps StarRocks as an independent SQL datasource capability', () => {
    expect(getDataSourceCapabilities({ type: 'starrocks' })).toMatchObject({
      type: 'starrocks',
      supportsQueryEditor: true,
      supportsSqlQueryExport: true,
      supportsCopyInsert: true,
      preferManualTotalCount: false,
    });
  });

  it('keeps InterSystems IRIS as an editable SQL datasource capability', () => {
    expect(getDataSourceCapabilities({ type: 'iris' })).toMatchObject({
      type: 'iris',
      supportsQueryEditor: true,
      supportsSqlQueryExport: true,
      supportsCopyInsert: true,
      forceReadOnlyQueryResult: false,
    });
    expect(getDataSourceCapabilities({ type: 'custom', driver: 'intersystemsiris' })).toMatchObject({
      type: 'iris',
      supportsQueryEditor: true,
    });
  });

  it('treats OceanBase Oracle protocol as Oracle capabilities', () => {
    expect(getDataSourceCapabilities({
      type: 'oceanbase',
      oceanBaseProtocol: 'oracle',
    })).toMatchObject({
      type: 'oracle',
      preferManualTotalCount: true,
      supportsApproximateTableCount: true,
    });
  });

  it('treats custom OceanBase Oracle driver as Oracle capabilities', () => {
    expect(getDataSourceCapabilities({
      type: 'custom',
      driver: 'oceanbase',
      oceanBaseProtocol: 'oracle',
    })).toMatchObject({
      type: 'oracle',
      preferManualTotalCount: true,
      supportsApproximateTableCount: true,
    });
  });
});
