package com.android.chmo.http.service;

import com.android.chmo.app.ChmoApplication;
import com.android.chmo.http.HttpApi;
import com.android.chmo.http.RequestCallback;
import com.android.chmo.model.LoginUser;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;

import java.io.File;

/**
 * Created by Administrator on 2018/8/1.
 */

public class UserService {
    private static RequestParams getRequestParams() {
        RequestParams params = new RequestParams(HttpApi.BASE_URL + "memberInfo");
        return params;
    }


    public static Callback.Cancelable login(String mobile, String password, RequestCallback callback) {
        RequestParams params = getRequestParams();
        params.addQueryStringParameter("action", "doLogin");
        params.addBodyParameter("mobile", mobile);
        params.addBodyParameter("pass", password);
        return HttpApi.POST(params, callback);
    }

    public static Callback.Cancelable getCode(String mobile,String codeStr, RequestCallback callback) {
        RequestParams params = new RequestParams("http://sdk.entinfo.cn:8061/mdsmssend.ashx");
        params.addQueryStringParameter("sn", "SDK-FHD-010-00328");
        params.addQueryStringParameter("pwd", "54774CB6E781A142206F756B3E18142C");
        params.addQueryStringParameter("mobile", mobile);
        params.addQueryStringParameter("content", codeStr);
        return HttpApi.GET(params, callback);
    }


    public static Callback.Cancelable register(String pet,String mobile, String password, RequestCallback callback) {
        RequestParams params = getRequestParams();
        params.addQueryStringParameter("action", "doRegister");
        params.addBodyParameter("mobile", mobile);
        params.addBodyParameter("pass", password);
        params.addBodyParameter("pet", pet);

        return HttpApi.GET(params, callback);
    }


    public static Callback.Cancelable getUser(RequestCallback callback) {
        LoginUser user = ChmoApplication.getApp().getLoginUser();
        return getUserByPk(user.pk, callback);
    }

    public static Callback.Cancelable getUserByPk(String pk, RequestCallback callback) {
        LoginUser user = ChmoApplication.getApp().getLoginUser();
        RequestParams params =getRequestParams();
        params.addQueryStringParameter("action", "getuserinfo");
        params.addQueryStringParameter("PK", pk);
        return HttpApi.GET(params, callback);
    }

    public static Callback.Cancelable modifyName(String name,RequestCallback callback) {
        LoginUser user = ChmoApplication.getApp().getLoginUser();
        RequestParams params =getRequestParams();
        params.addQueryStringParameter("action", "doPutPet");
        params.addQueryStringParameter("PK", user.pk);
        params.addQueryStringParameter("Pet",name);
        return HttpApi.GET(params, callback);
    }

    public static Callback.Cancelable updateHead(String path,RequestCallback callback) {
        LoginUser user = ChmoApplication.getApp().getLoginUser();
        RequestParams params = new RequestParams(HttpApi.BASE_URL + "upload");
        params.addBodyParameter("action", "hp");
        params.addBodyParameter("memberpk", user.pk);
        params.setMultipart(true);
        params.addBodyParameter("file", new File(path));
        return HttpApi.POST(params, callback);
    }

    public static Callback.Cancelable resetPwd(String mobile, String password, RequestCallback callback) {
        RequestParams params = getRequestParams();
        params.addQueryStringParameter("action", "doGetPass");
        params.addBodyParameter("mobile", mobile);
        params.addBodyParameter("pass", password);

        return HttpApi.GET(params, callback);
    }


    /**
     * 屏蔽模特
     */
    public static Callback.Cancelable shieldModel(String modelPk, RequestCallback callback) {
        LoginUser user = ChmoApplication.getApp().getLoginUser();
        RequestParams params = getRequestParams();
        params.addQueryStringParameter("action", "doDefriendModel");
        params.addQueryStringParameter("memberpk", user.pk);
        params.addQueryStringParameter("modelpk", modelPk);
        return HttpApi.GET(params, callback);
    }

    /**
     * 举报模特
     */
    public static Callback.Cancelable reportModel(String modelPk, String reason, RequestCallback callback) {
        LoginUser user = ChmoApplication.getApp().getLoginUser();
        RequestParams params = getRequestParams();
        params.addQueryStringParameter("action", "report");
        params.addQueryStringParameter("accuserpk", user.pk);
        params.addQueryStringParameter("appelleepk", modelPk);
        params.addQueryStringParameter("reason", reason);
        return HttpApi.GET(params, callback);
    }
}