import { test } from '@japa/runner'
import { Group } from '../../../../src/mocking/lib/Group.js'
import { GroupKind } from '../../../../src/models/kinds.js'
import type { GroupSchema } from '../../../../src/models/store/Group.js'

test.group('Group', (group) => {
  let groupMock: Group

  group.each.setup(() => {
    groupMock = new Group()
  })

  test('group() returns a valid object', ({ assert }) => {
    const result = groupMock.group()
    assert.typeOf(result, 'object')
    assert.equal(result.kind, GroupKind)
    assert.property(result, 'key')
    assert.property(result, 'name')
    assert.property(result, 'color')
    assert.property(result, 'users')
  })

  test('group(init) allows overriding properties', ({ assert }) => {
    const init: Partial<GroupSchema> = {
      name: 'Custom Group',
      color: '#ff0000',
    }
    const result = groupMock.group(init)
    assert.equal(result.name, 'Custom Group')
    assert.equal(result.color, '#ff0000')
  })

  test('groups() returns a list', ({ assert }) => {
    const result = groupMock.groups(5)
    assert.isArray(result)
    assert.lengthOf(result, 5)
  })

  test('groups(size, init) allows overriding properties', ({ assert }) => {
    const init: Partial<GroupSchema> = {
      description: 'Batch Description',
    }
    const result = groupMock.groups(3, init)
    assert.lengthOf(result, 3)
    result.forEach((item) => {
      assert.equal(item.description, 'Batch Description')
    })
  })
})
