import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:qrscanner/config/api_config.dart';
import 'package:qrscanner/models/auth_session.dart';
import 'package:qrscanner/models/scan_response.dart';

class PassCodeService {
  Future<ScanResponse> scan({
    required AuthSession session,
    required String code,
  }) async {
    final response = await http.post(
      Uri.parse(ApiConfig.scanUrl),
      headers: {
        'Content-Type': 'application/json',
        'Authorization': session.authorizationHeader,
      },
      body: jsonEncode({'code': code}),
    );

    final Map<String, dynamic> body =
        jsonDecode(response.body) as Map<String, dynamic>;

    return ScanResponse.fromJson(body);
  }
}