import 'package:flutter_test/flutter_test.dart';
import 'package:superport_v2/features/dashboard/data/dtos/dashboard_summary_dto.dart';
import 'package:superport_v2/features/dashboard/domain/entities/dashboard_pending_approval.dart';

void main() {
  group('DashboardSummaryDto', () {
    test('maps pending approval roles into domain entities', () {
      final dto = DashboardSummaryDto.fromJson({
        'generated_at': '2025-01-01T00:00:00Z',
        'kpis': [],
        'recent_transactions': [],
        'pending_approvals': [
          {
            'approval_id': 1,
            'approval_no': 'APP-001',
            'title': '입고 결재',
            'step_summary': '1단계 → 2단계',
            'requested_at': '2025-01-01T03:00:00Z',
            'roles': ['assigned', 'requested', 'completed'],
          },
        ],
      });

      final entity = dto.toEntity();
      final approval = entity.pendingApprovals.single;

      expect(
        approval.roles,
        containsAll(<DashboardApprovalRole>[
          DashboardApprovalRole.assigned,
          DashboardApprovalRole.requester,
          DashboardApprovalRole.completed,
        ]),
      );
    });

    test('ignores unknown role tokens gracefully', () {
      final dto = DashboardSummaryDto.fromJson({
        'generated_at': '2025-01-01T00:00:00Z',
        'kpis': [],
        'recent_transactions': [],
        'pending_approvals': [
          {
            'approval_id': 2,
            'approval_no': 'APP-002',
            'title': '출고 결재',
            'step_summary': '3단계',
            'requested_at': '2025-01-02T03:00:00Z',
            'roles': ['REQUESTER', 'unknown', ''],
          },
        ],
      });

      final approval = dto.toEntity().pendingApprovals.single;

      expect(approval.roles, [DashboardApprovalRole.requester]);
    });
  });
}
