package com.rv.home.rv.module.ui.main.home.presenter;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.ruiwenliu.wrapper.base.presenter.CommonPresenter;
import com.ruiwenliu.wrapper.util.UtilsManager;
import com.rv.component.utils.DateUtils;
import com.rv.home.rv.module.ui.main.home.CarRentalListActivity;
import com.rv.home.rv.module.ui.main.home.bean.CityPickerBean;
import com.rv.home.rv.module.ui.main.home.bean.ListsBean;
import com.rv.home.rv.module.ui.main.home.bean.OrderDataBean;

public class CarRentPresenter extends CommonPresenter {

    /**
     * 传参
     *
     * @param starCity
     * @param starAddress
     * @param endCity
     * @param endAddress
     * @param getTime
     * @param outTime
     * @param day
     * @param startTime
     * @param endTime
     */
    public void sendData(int getCityId,int outCityId,int getCompanyId ,int outCompanyId,
                          double latLatitude,double lonLongitude,
                          String starCity, String starAddress, String endCity, String endAddress,
                          String getTime, String outTime, long day, String startTime, String endTime) {
        OrderDataBean dataBean = new OrderDataBean();
        if (getCityId > 0) {
            dataBean.setStartCity(getCityId);
        }
        if (outCityId > 0) {
            dataBean.setEndCity(outCityId);
        } else {
            String json = UtilsManager.getInstance().getJson(getPresenterContext(), "city.json");
            CityPickerBean bean = new Gson().fromJson(json, CityPickerBean.class);
            for (CityPickerBean.CityBean cityBean : bean.getCity()) {
                for (ListsBean lsBean : cityBean.getLists()) {
                    if (!TextUtils.isEmpty(starCity) && starCity.equals(lsBean.getName())) {
                        dataBean.setStartCity(lsBean.getId());
                    }

                    if (!TextUtils.isEmpty(endCity) && endCity.equals(lsBean.getName())) {
                        dataBean.setEndCity(lsBean.getId());
                    }
                }
            }
        }
        dataBean.setDayNum(Integer.valueOf(day + ""));
        dataBean.setStartCityName(starCity);
        dataBean.setStartAddr(starAddress);
        dataBean.setStartTime(DateUtils.StringToTimeMillis2(getTime));
        dataBean.setEndTime(DateUtils.StringToTimeMillis2(outTime));
        dataBean.setEndCityName(endCity);
        dataBean.setEndCompanyId(outCompanyId);
        dataBean.setEndAddr(endAddress);
        dataBean.setDriverType(2);
        dataBean.setStartCompanyId(getCompanyId);
        getPresenterContext().startActivity(CarRentalListActivity.getIntent(getPresenterContext(), latLatitude, lonLongitude, false, dataBean, startTime, endTime));
    }
}
