import 'package:flutter_test/flutter_test.dart';

import 'package:superport_v2/core/permissions/permission_manager.dart';
import 'package:superport_v2/core/permissions/permission_resources.dart';
import 'package:superport_v2/features/masters/group_permission/domain/entities/group_permission.dart';
import 'package:superport_v2/features/masters/group_permission/domain/mappers/group_permission_mapper.dart';

void main() {
  test('메뉴 경로 기준으로 권한 맵을 생성한다', () {
    final permissions = [
      GroupPermission(
        id: 1,
        group: GroupPermissionGroup(id: 1, groupName: '관리자'),
        menu: GroupPermissionMenu(
          id: 10,
          menuCode: 'INBOUND',
          menuName: '입고',
          path: '/inventory/inbound',
        ),
        canCreate: true,
        canRead: true,
        canUpdate: false,
        canDelete: false,
      ),
      GroupPermission(
        id: 2,
        group: GroupPermissionGroup(id: 1, groupName: '관리자'),
        menu: GroupPermissionMenu(
          id: 11,
          menuCode: 'OUTBOUND',
          menuName: '출고',
          path: '/inventory/outbound',
        ),
        canCreate: false,
        canRead: true,
        canUpdate: true,
        canDelete: true,
      ),
      GroupPermission(
        id: 3,
        group: GroupPermissionGroup(id: 1, groupName: '관리자'),
        menu: GroupPermissionMenu(
          id: 12,
          menuCode: 'NO_PATH',
          menuName: '경로없음',
          path: null,
        ),
        canCreate: true,
        canRead: true,
        canUpdate: true,
        canDelete: true,
      ),
    ];

    final map = buildPermissionMap(permissions);

    expect(map.length, 1);
    final stockPermissions =
        map[PermissionResources.stockTransactions] ?? <PermissionAction>{};
    expect(
      stockPermissions,
      containsAll(<PermissionAction>{
        PermissionAction.view,
        PermissionAction.create,
        PermissionAction.edit,
        PermissionAction.delete,
      }),
    );
    expect(map.containsKey('NO_PATH'), isFalse);
  });
}
