import 'package:flutter_test/flutter_test.dart';
import 'package:superport_v2/features/approvals/step/domain/entities/approval_step_input.dart';

void main() {
  group('ApprovalStepInput.toPayload', () {
    test('statusId가 있으면 status_id와 step_status_id를 동시에 전송한다', () {
      final assigned = DateTime.parse('2025-10-20T09:00:00Z');
      final decided = DateTime.parse('2025-10-21T10:30:00Z');
      final input = ApprovalStepInput(
        approvalId: 42,
        stepOrder: 1,
        approverId: 7,
        statusId: 3,
        assignedAt: assigned,
        decidedAt: decided,
        note: '추가 확인 필요',
      );

      final payload = input.toPayload();

      expect(payload['approval_id'], 42);
      expect(payload['status_id'], 3);
      expect(payload['step_status_id'], 3);
      expect(payload['assigned_at'], assigned.toUtc().toIso8601String());
      expect(payload['decided_at'], decided.toUtc().toIso8601String());
      expect(payload['note'], '추가 확인 필요');
    });

    test('선택 필드를 생략하면 페이로드에서 제외한다', () {
      final input = ApprovalStepInput(
        stepOrder: 2,
        approverId: 11,
        note: '   ', // 공백만 있는 노트는 제거된다.
      );

      final payload = input.toPayload();

      expect(payload.containsKey('approval_id'), isFalse);
      expect(payload.containsKey('status_id'), isFalse);
      expect(payload.containsKey('step_status_id'), isFalse);
      expect(payload.containsKey('assigned_at'), isFalse);
      expect(payload.containsKey('decided_at'), isFalse);
      expect(payload.containsKey('note'), isFalse);
      expect(payload['step_order'], 2);
      expect(payload['approver_id'], 11);
    });
  });
}
