import { describe, it, expect } from 'vitest';
import { buildFavouriteIndex } from '../src/commands/create.js';

describe('buildFavouriteIndex — CLI flags → project favouriteIndex', () => {
  it('returns undefined when no favourite flag is given', () => {
    expect(buildFavouriteIndex({})).toBeUndefined();
  });

  it('enables and sets the pins when --favourite is given', () => {
    expect(buildFavouriteIndex({ favourite: ['k8s/get_pods', 'vault/read_secret'] })).toEqual({
      enabled: true,
      tools: ['k8s/get_pods', 'vault/read_secret'],
    });
  });

  it('--no-favourite-index disables', () => {
    expect(buildFavouriteIndex({ favouriteIndex: false })).toEqual({ enabled: false });
  });

  it('parses --max-favourites into an integer', () => {
    expect(buildFavouriteIndex({ favouriteIndex: true, maxFavourites: '15' })).toEqual({
      enabled: true,
      maxFavourites: 15,
    });
  });

  it('throws on a non-positive-integer --max-favourites', () => {
    expect(() => buildFavouriteIndex({ maxFavourites: 'abc' })).toThrow(/max-favourites/);
    expect(() => buildFavouriteIndex({ maxFavourites: '0' })).toThrow(/max-favourites/);
  });
});
