// GENERATED CODE - DO NOT MODIFY BY HAND

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

import 'dart:convert';

import 'dart:io';

import 'package:rxdart/rxdart.dart';

import 'package:dio/dio.dart';

import 'package:flutter/foundation.dart';

import 'package:gmalpha_flutter/MessageModel/service/remote/entity/MyMessageEntity.dart';
import 'package:gmalpha_flutter/MessageModel/service/remote/entity/UnreadMessageEntity.dart';
import 'package:gmalpha_flutter/MessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/MessageModel/service/remote/entity/LikePageEntity.dart';
import 'package:gmalpha_flutter/MessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/MessageModel/service/remote/entity/FocusPageEntity.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})).flatMap((value) {
      if (value != null && value.statusCode == 200) {
        return Observable.fromFuture(
            compute(paseMyMessageEntity, value.toString()));
      } else {
        return Observable.fromFuture(null);
      }
    });
  }

  Observable<UnreadMessageEntity> getUnreadMessage(int type) {
    return Observable.fromFuture(
            DioUtil().get('api/v1/message/unread', data: {'type': type}))
        .flatMap((value) {
      if (value != null && value.statusCode == 200) {
        return Observable.fromFuture(
            compute(paseUnreadMessageEntity, value.toString()));
      } else {
        return Observable.fromFuture(null);
      }
    });
  }

  Observable<LatestMessageEntity> getLatestMessage() {
    return Observable.fromFuture(DioUtil().get('api/v1/push/newest/info'))
        .flatMap((value) {
      if (value != null && value.statusCode == 200) {
        return Observable.fromFuture(
            compute(paseLatestMessageEntity, value.toString()));
      } else {
        return Observable.fromFuture(null);
      }
    });
  }

  Observable<LikePageEntity> getLikePage(int page, int count) {
    return Observable.fromFuture(DioUtil().get('api/v1/message/like',
        data: {'page': page, 'count': count})).flatMap((value) {
      if (value != null && value.statusCode == 200) {
        return Observable.fromFuture(
            compute(paseLikePageEntity, value.toString()));
      } else {
        return Observable.fromFuture(null);
      }
    });
  }

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

  Observable<FocusPageEntity> getFocusPage(int type, int page, int count) {
    return Observable.fromFuture(DioUtil().get('/api/v1/follow/list',
        data: {'type': type, 'page': page, 'count': count})).flatMap((value) {
      if (value != null && value.statusCode == 200) {
        return Observable.fromFuture(
            compute(paseFocusPageEntity, value.toString()));
      } else {
        return Observable.fromFuture(null);
      }
    });
  }
}

MyMessageEntity paseMyMessageEntity(String value) {
  return MyMessageEntity.fromJson(json.decode(value));
}

UnreadMessageEntity paseUnreadMessageEntity(String value) {
  return UnreadMessageEntity.fromJson(json.decode(value));
}

LatestMessageEntity paseLatestMessageEntity(String value) {
  return LatestMessageEntity.fromJson(json.decode(value));
}

LikePageEntity paseLikePageEntity(String value) {
  return LikePageEntity.fromJson(json.decode(value));
}

AttentionEntity paseAttentionEntity(String value) {
  return AttentionEntity.fromJson(json.decode(value));
}

FocusPageEntity paseFocusPageEntity(String value) {
  return FocusPageEntity.fromJson(json.decode(value));
}
