import { test } from '@japa/runner'
import { File, Folder, ICapabilities, PermissionRole, Project } from '../../../../src/index.js'

test.group('File.createFileCapabilities()', () => {
  test('{$i} correctly sets file capabilities')
    .tags(['@model', '@file'])
    .with([
      ['canReadMedia', 'reader', true],
      ['canReadMedia', 'commenter', true],
      ['canReadMedia', 'writer', true],
      ['canReadMedia', 'owner', true],

      ['canListChildren', 'reader', false],
      ['canListChildren', 'commenter', false],
      ['canListChildren', 'writer', false],
      ['canListChildren', 'owner', false],

      ['canComment', 'reader', false],
      ['canComment', 'commenter', true],
      ['canComment', 'writer', true],
      ['canComment', 'owner', true],

      ['canEditMedia', 'reader', false],
      ['canEditMedia', 'commenter', false],
      ['canEditMedia', 'writer', true],
      ['canEditMedia', 'owner', true],

      ['canEditMeta', 'reader', false],
      ['canEditMeta', 'commenter', false],
      ['canEditMeta', 'writer', true],
      ['canEditMeta', 'owner', true],

      ['canReadRevisions', 'reader', false],
      ['canReadRevisions', 'commenter', false],
      ['canReadRevisions', 'writer', true],
      ['canReadRevisions', 'owner', true],

      ['canAddChildren', 'reader', false],
      ['canAddChildren', 'commenter', false],
      ['canAddChildren', 'writer', false],
      ['canAddChildren', 'owner', false],

      ['canDelete', 'reader', false],
      ['canDelete', 'commenter', false],
      ['canDelete', 'writer', false],
      ['canDelete', 'owner', true],

      ['canTrash', 'reader', false],
      ['canTrash', 'commenter', false],
      ['canTrash', 'writer', false],
      ['canTrash', 'owner', true],

      ['canUntrash', 'reader', false],
      ['canUntrash', 'commenter', false],
      ['canUntrash', 'writer', false],
      ['canUntrash', 'owner', true],

      ['canShare', 'reader', false],
      ['canShare', 'commenter', false],
      ['canShare', 'writer', true],
      ['canShare', 'owner', true],

      ['canMove', 'reader', false],
      ['canMove', 'commenter', false],
      ['canMove', 'writer', true],
      ['canMove', 'owner', true],
    ])
    .run(({ assert }, row) => {
      const file = new Project()
      const result = File.createFileCapabilities(file, row[1] as PermissionRole)
      const key = row[0] as keyof ICapabilities
      assert.strictEqual(result[key], row[2])
    })

  test('{$i} correctly sets folder capabilities')
    .tags(['@model', '@file'])
    .with([
      ['canReadMedia', 'reader', false],
      ['canReadMedia', 'commenter', false],
      ['canReadMedia', 'writer', false],
      ['canReadMedia', 'owner', false],

      ['canListChildren', 'reader', true],
      ['canListChildren', 'commenter', true],
      ['canListChildren', 'writer', true],
      ['canListChildren', 'owner', true],

      ['canComment', 'reader', false],
      ['canComment', 'commenter', false],
      ['canComment', 'writer', false],
      ['canComment', 'owner', false],

      ['canEditMedia', 'reader', false],
      ['canEditMedia', 'commenter', false],
      ['canEditMedia', 'writer', false],
      ['canEditMedia', 'owner', false],

      ['canEditMeta', 'reader', false],
      ['canEditMeta', 'commenter', false],
      ['canEditMeta', 'writer', true],
      ['canEditMeta', 'owner', true],

      ['canReadRevisions', 'reader', false],
      ['canReadRevisions', 'commenter', false],
      ['canReadRevisions', 'writer', true],
      ['canReadRevisions', 'owner', true],

      ['canAddChildren', 'reader', false],
      ['canAddChildren', 'commenter', false],
      ['canAddChildren', 'writer', true],
      ['canAddChildren', 'owner', true],

      ['canDelete', 'reader', false],
      ['canDelete', 'commenter', false],
      ['canDelete', 'writer', false],
      ['canDelete', 'owner', true],

      ['canTrash', 'reader', false],
      ['canTrash', 'commenter', false],
      ['canTrash', 'writer', false],
      ['canTrash', 'owner', true],

      ['canUntrash', 'reader', false],
      ['canUntrash', 'commenter', false],
      ['canUntrash', 'writer', false],
      ['canUntrash', 'owner', true],

      ['canShare', 'reader', false],
      ['canShare', 'commenter', false],
      ['canShare', 'writer', true],
      ['canShare', 'owner', true],

      ['canMove', 'reader', false],
      ['canMove', 'commenter', false],
      ['canMove', 'writer', true],
      ['canMove', 'owner', true],
    ])
    .run(({ assert }, row) => {
      const file = new Folder()
      const result = File.createFileCapabilities(file, row[1] as PermissionRole)
      const key = row[0] as keyof ICapabilities
      assert.strictEqual(result[key], row[2])
    })
})
