import { validateConfig } from '../config'

const base = {
  slack: {
    session_name: 'sddbot',
    bot_token: 'xoxb-token',
    app_token: 'xapp-token',
  },
  llm: {
    provider: 'ollama',
    model: 'llama3',
  },
  sdd: {
    worktrees_root: '.worktree',
  },
}

describe('validateConfig', () => {
  test('aceita GitHub sem Jira/Bitbucket quando selecionado', () => {
    expect(() => validateConfig({
      ...base,
      integrations: { work_tracker: 'github', repo: 'github' },
      github: {
        owner: 'acme',
        repo: 'api',
        base_branch: 'main',
        auth: { token_env: 'GITHUB_TOKEN' },
      },
    }, '/tmp/config.yaml')).not.toThrow()
  })

  test('mantém config Jira/Bitbucket legado válido', () => {
    expect(() => validateConfig({
      ...base,
      jira: {
        base_url: 'https://acme.atlassian.net',
        project_key: 'ACME',
        backlog_column: 'Backlog',
        api_token: 'token',
        user: 'user@example.com',
      },
      bitbucket: {
        workspace: 'acme',
        repo_slug: 'api',
        base_branch: 'main',
        app_password: 'token',
        user: 'user@example.com',
      },
    }, '/tmp/config.yaml')).not.toThrow()
  })

  test('não troca Jira/Bitbucket por GitHub só porque existe seção github', () => {
    expect(() => validateConfig({
      ...base,
      jira: {
        base_url: 'https://acme.atlassian.net',
        project_key: 'ACME',
        backlog_column: 'Backlog',
        api_token: 'token',
        user: 'user@example.com',
      },
      bitbucket: {
        workspace: 'acme',
        repo_slug: 'api',
        base_branch: 'main',
        app_password: 'token',
        user: 'user@example.com',
      },
      github: {
        owner: 'acme',
        repo: 'api',
        base_branch: 'main',
      },
    }, '/tmp/config.yaml')).not.toThrow()
  })
})
