package com.police.policedatasystem.mine.viewmodel;

import androidx.annotation.NonNull;

import com.police.policedatasystem.apply.model.ApplyType;
import com.police.policedatasystem.http.CustomCallBack;
import com.police.policedatasystem.http.RequestClient;
import com.police.policedatasystem.indexActivity;
import com.police.policedatasystem.mine.fragment.MineFragment;
import com.police.policedatasystem.mine.model.Apply;
import com.police.policedatasystem.util.UiUtils;

import java.util.HashMap;
import java.util.List;

import okhttp3.Call;

public class MineViewModel {
    private final MineFragment fragment;
    public indexActivity activity;

    public MineViewModel(MineFragment fragment, indexActivity activity) {
        this.fragment = fragment;
        this.activity = activity;
    }

    public void getApplyList(HashMap<String, String> params) {
        fragment.loadingShow();
        RequestClient.instance().getApplyList(params, new CustomCallBack<List<Apply>>() {
            @Override
            public void onError(@NonNull Call call, @NonNull Exception e) {
                UiUtils.toast(e.getMessage());
                fragment.loadingNone();
            }

            @Override
            public void onSuccess(List<Apply> value) {
                fragment.applyList(value);
                fragment.loadingNone();
            }
        });
    }

    public void getApplyType() {
        fragment.loadingShow();
        RequestClient.instance().getApplyType(new CustomCallBack<List<ApplyType>>() {
            @Override
            public void onError(@NonNull Call call, @NonNull Exception e) {
                UiUtils.toast(e.getMessage());
                fragment.loadingNone();
            }

            @Override
            public void onSuccess(List<ApplyType> value) {
                fragment.applyType(value);
                fragment.loadingNone();
            }
        });
    }

    public void getMineBLZT() {
        fragment.loadingShow();
        RequestClient.instance().getMineBLZT(new CustomCallBack<List<ApplyType>>() {
            @Override
            public void onError(@NonNull Call call, @NonNull Exception e) {
                UiUtils.toast(e.getMessage());
                fragment.loadingNone();
            }

            @Override
            public void onSuccess(List<ApplyType> value) {
                fragment.applyBLZT(value);
                fragment.loadingNone();
            }
        });
    }

    public void getMineXXLY() {
        fragment.loadingShow();
        RequestClient.instance().getMineXXLY(new CustomCallBack<List<ApplyType>>() {
            @Override
            public void onError(@NonNull Call call, @NonNull Exception e) {
                UiUtils.toast(e.getMessage());
                fragment.loadingNone();
            }

            @Override
            public void onSuccess(List<ApplyType> value) {
                fragment.applyXXLY(value);
                fragment.loadingNone();
            }
        });
    }
}
