import { test } from '@japa/runner'
import { File } from '../../../../src/mocking/lib/File.js'
import { FolderKind, ProjectKind } from '../../../../src/models/kinds.js'
import type { IFile } from '../../../../src/models/store/File.js'

test.group('File', (group) => {
  let fileMock: File

  group.each.setup(() => {
    fileMock = new File()
  })

  test('file() returns a valid object', ({ assert }) => {
    const result = fileMock.file()
    assert.typeOf(result, 'object')
    assert.property(result, 'kind')
    assert.property(result, 'info')
  })

  test('file(init) allows overriding properties', ({ assert }) => {
    const init: Partial<IFile> = {
      kind: ProjectKind,
      info: { name: 'My Project' },
    }
    const result = fileMock.file(init)
    assert.equal(result.kind, ProjectKind)
    assert.equal(result.info.name, 'My Project')
  })

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

  test('files(size, init) allows overriding properties', ({ assert }) => {
    const init: Partial<IFile> = {
      kind: ProjectKind,
    }
    const result = fileMock.files(3, init)
    assert.lengthOf(result, 3)
    result.forEach((item) => {
      assert.equal(item.kind, ProjectKind)
    })
  })

  test('folder() returns a valid object', ({ assert }) => {
    const result = fileMock.folder()
    assert.typeOf(result, 'object')
    assert.equal(result.kind, FolderKind)
  })

  test('folder(init) allows overriding properties', ({ assert }) => {
    const init: Partial<IFile> = {
      key: 'custom-folder-key',
    }
    const result = fileMock.folder(init)
    assert.equal(result.kind, FolderKind)
    assert.equal(result.key, 'custom-folder-key')
  })

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

  test('folders(size, init) allows overriding properties', ({ assert }) => {
    const init: Partial<IFile> = {
      key: 'batch-key',
    }
    const result = fileMock.folders(3, init)
    assert.lengthOf(result, 3)
    result.forEach((item) => {
      assert.equal(item.kind, FolderKind)
      assert.equal(item.key, 'batch-key')
    })
  })
})
