import 'package:flutter_test/flutter_test.dart';
import 'package:superport_v2/features/inventory/transactions/data/dtos/stock_transaction_dto.dart';

void main() {
  group('StockTransactionDto', () {
    test('결재 상세 정보를 포함해 파싱한다', () {
      final dto = StockTransactionDto.fromJson({
        'id': 9001,
        'transaction_no': 'TRX-202511100001',
        'transaction_date': '2025-09-18',
        'transaction_type': {'id': 1, 'name': '입고'},
        'transaction_status': {'id': 1, 'name': '초안'},
        'warehouse': {
          'id': 1,
          'warehouse_code': 'WH-001',
          'warehouse_name': '1센터',
        },
        'created_by': {
          'id': 7,
          'employee_no': 'E20250001',
          'employee_name': '김상신',
        },
        'lines': [
          {
            'id': 12001,
            'line_no': 1,
            'product': {
              'id': 101,
              'product_code': 'P100',
              'product_name': '샘플',
            },
            'quantity': 10,
            'unit_price': 1200,
          },
        ],
        'customers': [],
        'approval': {
          'id': 5001,
          'approval_no': 'APP-202511100001',
          'status': {
            'id': 1,
            'name': '대기',
            'is_blocking_next': true,
            'is_terminal': false,
          },
          'current_step': {
            'id': 7001,
            'step_order': 1,
            'status': {
              'id': 2,
              'name': '진행중',
              'is_blocking_next': true,
              'is_terminal': false,
            },
            'approver': {'id': 21, 'employee_no': 'E2025002', 'name': '박검토'},
            'assigned_at': '2025-09-18T06:05:00Z',
          },
          'requester': {'id': 7, 'employee_no': 'E20250001', 'name': '김상신'},
          'requested_at': '2025-09-18T06:00:00Z',
          'note': '입고 결재',
          'template_name': '입고 결재 기본',
          'steps': [
            {
              'id': 7201,
              'step_order': 1,
              'status': {
                'id': 3,
                'name': '승인',
                'is_blocking_next': false,
                'is_terminal': false,
              },
              'approver': {'id': 21, 'employee_no': 'E2025002', 'name': '박검토'},
              'assigned_at': '2025-09-18T06:05:00Z',
              'decided_at': '2025-09-18T06:10:00Z',
            },
            {
              'id': 7202,
              'step_order': 2,
              'status': {
                'id': 1,
                'name': '대기',
                'is_blocking_next': true,
                'is_terminal': false,
              },
              'approver': {'id': 22, 'employee_no': 'E2025003', 'name': '이승인'},
              'assigned_at': '2025-09-18T06:10:00Z',
            },
          ],
          'histories': [
            {
              'id': 93001,
              'action': {'id': 1, 'name': '상신'},
              'to_status': {
                'id': 1,
                'name': '대기',
                'is_blocking_next': true,
                'is_terminal': false,
              },
              'approver': {'id': 7, 'employee_no': 'E20250001', 'name': '김상신'},
              'action_at': '2025-09-18T06:00:00Z',
            },
          ],
          'created_at': '2025-09-18T06:00:00Z',
          'updated_at': '2025-09-18T06:05:00Z',
        },
      });

      final entity = dto.toEntity();

      expect(entity.approval, isNotNull);
      final approval = entity.approval!;
      expect(approval.approvalNo, 'APP-202511100001');
      expect(approval.status.name, '대기');
      expect(approval.currentStep?.stepOrder, 1);
      expect(approval.currentStep?.approver.name, '박검토');
      expect(approval.steps.length, 2);
      expect(approval.histories.length, 1);
      expect(approval.requester.name, '김상신');
      expect(
        approval.requestedAt.toUtc().toIso8601String(),
        '2025-09-18T06:00:00.000Z',
      );
    });
  });
}
