package com.android.chmo.ui.activity.model;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.android.chmo.R;
import com.android.chmo.base.BaseActivity;
import com.android.chmo.http.RequestCallback;
import com.android.chmo.http.response.Res;
import com.android.chmo.http.service.UserService;
import com.android.chmo.ui.view.TopBar;
import com.google.gson.Gson;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/9/4.
 */

public class ModelReportActivity extends BaseActivity {
    @BindView(R.id.topBar)
    TopBar topBar;
    @BindView(R.id.reason)
    EditText editText;

    private String modelPk;


    @Override
    protected int getContentResId() {
        return R.layout.activity_report;
    }

    @Override
    public void initView() {
        modelPk = this.getIntent().getStringExtra("modelPk");

        topBar.setRightBtn("提交", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                submit();
            }
        });
    }


    private void submit() {
        String reason = editText.getText().toString();
        if (TextUtils.isEmpty(reason)) {
            showToast("请输入举报内容");
            return;
        }

        showLoading();
        UserService.reportModel(modelPk, reason, new RequestCallback() {
            @Override
            public void onSuccess(String result) {
                hideLoading();
                Res res = new Gson().fromJson(result,Res.class);
                if (res.msg.equals("success")) {
                    showToast("举报成功");
                    finish();
                }else {
                    showToast("举报失败");
                }
            }

            @Override
            public void onFailure(String error) {
                hideLoading();
                showToast("举报失败");
            }
        });
    }
}
