import 'package:flutter_test/flutter_test.dart';

import 'package:superport_v2/features/approvals/data/dtos/approval_draft_dto.dart';
import 'package:superport_v2/features/approvals/domain/entities/approval_draft.dart';

void main() {
  group('ApprovalDraftDto', () {
    test('parsePaginated가 요약 리스트를 변환한다', () {
      final result = ApprovalDraftDto.parsePaginated({
        'items': [
          {
            'id': 10,
            'requester_id': 77,
            'status': 'active',
            'saved_at': '2025-01-01T00:00:00Z',
            'step_count': 2,
            'session_key': 'session-1',
          },
        ],
        'page': 2,
        'page_size': 50,
        'total': 90,
      });

      expect(result.page, 2);
      expect(result.pageSize, 50);
      expect(result.total, 90);
      expect(result.items, hasLength(1));
      final summary = result.items.first;
      expect(summary.id, 10);
      expect(summary.requesterId, 77);
      expect(summary.status, ApprovalDraftStatus.active);
      expect(summary.stepCount, 2);
      expect(summary.sessionKey, 'session-1');
    });

    test('parseDetail이 상세 정보를 반환한다', () {
      final detail = ApprovalDraftDto.parseDetail({
        'data': {
          'id': 5,
          'requester_id': 11,
          'saved_at': '2025-01-02T12:00:00Z',
          'payload': {
            'title': '대여 결재',
            'summary': '사전 확인',
            'metadata': {
              '_client_state': {'status_id': 4},
            },
            'steps': [
              {'step_order': 1, 'approver_id': 20, 'note': '검토'},
            ],
          },
        },
      });

      expect(detail, isNotNull);
      final value = detail!;
      expect(value.id, 5);
      expect(value.requesterId, 11);
      expect(value.payload.title, '대여 결재');
      expect(value.payload.steps, hasLength(1));
      expect(value.payload.steps.first.approverId, 20);
    });
  });
}
