import { describe, expect, test } from 'bun:test';
import { TakeStore, acceptProposal } from '../src/takes/proposals';

function seeded(): TakeStore {
  const store = new TakeStore();
  store.takes.set('t1', { id: 't1', claim: 'the sky is blue', active: true });
  return store;
}

describe('take proposals', () => {
  test('accepting an add proposal creates the take', () => {
    const store = seeded();
    store.proposals.set('p1', { id: 'p1', kind: 'takes_add', takeId: 't2', claim: 'water is wet', status: 'pending' });
    acceptProposal(store, 'p1');
    expect(store.takes.get('t2')).toEqual({ id: 't2', claim: 'water is wet', active: true });
  });

  test('accepting a remove proposal deletes the take', () => {
    const store = seeded();
    store.proposals.set('p1', { id: 'p1', kind: 'takes_remove', takeId: 't1', status: 'pending' });
    acceptProposal(store, 'p1');
    expect(store.takes.has('t1')).toBe(false);
  });
});
