package com.police.policedatasystem.apply.viewmodel;

import androidx.annotation.NonNull;

import com.police.policedatasystem.apply.activity.ApplyActivity;
import com.police.policedatasystem.apply.model.ApplyDept;
import com.police.policedatasystem.apply.model.ApplyPerson;
import com.police.policedatasystem.apply.model.ApplyType;
import com.police.policedatasystem.http.CustomCallBack;
import com.police.policedatasystem.util.UiUtils;

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

import okhttp3.Call;

public class ApplyPostViewModel {
    public ApplyActivity activity;

    public ApplyPostViewModel(ApplyActivity activity) {
        this.activity = activity;
    }


    public void getApplyDept() {
        activity.loadingShow();
        activity.requestClient.getApplyDept(new CustomCallBack<List<ApplyDept>>() {
            @Override
            public void onError(@NonNull Call call, @NonNull Exception e) {
                UiUtils.toast(e.getMessage());
                activity.loadingNone();
            }

            @Override
            public void onSuccess(List<ApplyDept> value) {
                activity.applyDept = value;
                activity.loadingNone();
            }
        });
    }

    public void getApplyPerson(String deptId) {
        activity.loadingShow();
        activity.requestClient.getApplyPerson(deptId, new CustomCallBack<List<ApplyPerson>>() {
            @Override
            public void onError(@NonNull Call call, @NonNull Exception e) {
                UiUtils.toast(e.getMessage());
                activity.loadingNone();
            }

            @Override
            public void onSuccess(List<ApplyPerson> value) {
                activity.applyPeople = value;
                activity.loadingNone();
            }
        });
    }
//
//    public void getApplyJWLX() {
//        activity.loadingShow();
//        activity.requestClient.getApplyJWLX(new CustomCallBack<List<ApplyType>>() {
//            @Override
//            public void onError(@NonNull Call call, @NonNull Exception e) {
//                UiUtils.toast(e.getMessage());
//                activity.loadingNone();
//            }
//
//            @Override
//            public void onSuccess(List<ApplyType> value) {
//                activity.applyJWLX = value;
//                activity.loadingNone();
//            }
//        });
//    }
//
//    public void getApplyXXLY() {
//        activity.loadingShow();
//        activity.requestClient.getApplyXXLY(new CustomCallBack<List<ApplyType>>() {
//            @Override
//            public void onError(@NonNull Call call, @NonNull Exception e) {
//                UiUtils.toast(e.getMessage());
//                activity.loadingNone();
//            }
//
//            @Override
//            public void onSuccess(List<ApplyType> value) {
//                activity.applyXXLY = value;
//                activity.loadingNone();
//            }
//        });
//    }

    public void addApply(HashMap<String, String> map) {
        activity.loadingShow();
        activity.requestClient.addApply(map, new CustomCallBack<Object>() {
            @Override
            public void onError(@NonNull Call call, @NonNull Exception e) {
                UiUtils.toast(e.getMessage());
                activity.loadingNone();
            }

            @Override
            public void onSuccess(Object value) {
                activity.sendSuccess();
                activity.loadingNone();
            }
        });
    }
}
