// GENERATED CODE - DO NOT MODIFY BY HAND

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

import 'dart:convert';

import 'dart:io';

import 'package:rxdart/rxdart.dart';

import 'package:gmalpha_flutter/userModel/service/remote/entity/UserResultBean.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/CommentBean.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/CountryBean.dart';

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

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

  static UserApiImpl _instance;

  UserApiImpl._() {}

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

  Observable<UserResultBean> getUserInfo(String userID) {
    return Observable.fromFuture(DioUtil().get('api/account/user_profile',
        data: {'user_id': userID})).map((value) {
      if (value != null && value.statusCode == 200) {
        Map map = json.decode(value.toString());
        return UserResultBean.fromJson(map);
      }
    });
  }

  Observable<CommentBean> comment(String content, String phone) {
    return Observable.fromFuture(DioUtil().post('api/v1/suggestion',
        data: {'content': content, 'phone': phone})).map((value) {
      if (value != null && value.statusCode == 200) {
        Map map = json.decode(value.toString());
        return CommentBean.fromJson(map);
      }
    });
  }

  Observable<CountryBean> getCountrys() {
    return Observable.fromFuture(DioUtil().get('api/v1/countries'))
        .map((value) {
      if (value != null && value.statusCode == 200) {
        Map map = json.decode(value.toString());
        return CountryBean.fromJson(map);
      }
    });
  }
}
