import 'dart:convert';
import 'dart:core';

import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;

class MemorandaAdminApiServices {
  static final MemorandaAdminApiServices _instance =
      MemorandaAdminApiServices();
  static MemorandaAdminApiServices get instance => _instance;
  String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
  String xClientKeySecret = "unitcYqAN7GGalyz";

  Future<List> fetch() async {
    String path = Url.instance.getMemoranda();
    Map<String, String> headers = {
      'Content-Type': 'application/json; charset=UTF-8',
      'X-Client-Key': xClientKey,
      'X-Client-Secret': xClientKeySecret
    };

    try {
      http.Response response = await Request.instance
          .getRequest(param: {}, path: path, headers: headers);

      print(response.body);
      if (response.statusCode == 200) {
        final List result = jsonDecode(response.body)['data'];
        print(result);
        return result;
      } else {
        throw Exception(response.reasonPhrase);
      }
    } catch (e) {
      throw Exception(e.toString());
    }
  }
}
