// GENERATED CODE - DO NOT MODIFY BY HAND

// **************************************************************************
// ServiceGenerator
// **************************************************************************

import 'dart:convert';

import 'dart:io';

import 'package:rxdart/rxdart.dart';

import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/MyMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/UnreadMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';

import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';

class MessageApiImpl {
  factory MessageApiImpl() => _sharedInstance();

  static MessageApiImpl _instance;

  MessageApiImpl._() {}

  static MessageApiImpl _sharedInstance() {
    if (_instance == null) {
      _instance = MessageApiImpl._();
    }
    return _instance;
  }

  Observable<MyMessageEntity> getMyMessage(int page, int count) {
    return Observable.fromFuture(DioUtil().get('api/v1/message/my',
        data: {'page': page, 'count': count})).map((value) {
      if (value != null && value.statusCode == 200) {
        Map map = json.decode(value.toString());
        return MyMessageEntity.fromJson(map);
      }
    });
  }

  Observable<UnreadMessageEntity> getUnreadMessage(int type) {
    return Observable.fromFuture(
            DioUtil().get('api/v1/message/unread', data: {'type': type}))
        .map((value) {
      if (value != null && value.statusCode == 200) {
        Map map = json.decode(value.toString());
        return UnreadMessageEntity.fromJson(map);
      }
    });
  }

  Observable<LatestMessageEntity> getLatestMessage() {
    return Observable.fromFuture(DioUtil().get('api/v1/push/newest/info'))
        .map((value) {
      if (value != null && value.statusCode == 200) {
        Map map = json.decode(value.toString());
        return LatestMessageEntity.fromJson(map);
      }
    });
  }

  Observable<AttentionEntity> getAttentionList(int page, int count) {
    return Observable.fromFuture(DioUtil().get('api/v1/message/notice',
        data: {'page': page, 'count': count})).map((value) {
      if (value != null && value.statusCode == 200) {
        Map map = json.decode(value.toString());
        return AttentionEntity.fromJson(map);
      }
    });
  }
}
