package tw.com.altob.goodpk.Loader;

import android.content.Context;

import androidx.annotation.NonNull;

import com.ga.sdk.loader.BaseAsyncTaskLoader;

import tw.com.altob.goodpk.Api.GoodPkApi;
import tw.com.altob.goodpk.Bean.CW;
import tw.com.altob.goodpk.Parser.CarWhereParser;

public class GetCarWhereLoader extends BaseAsyncTaskLoader<CW> {

    private String mCarNo;
    private Context mContext;

    public GetCarWhereLoader(@NonNull Context context, String carNo) {
        super(context);

        this.mContext = context;
        this.mCarNo = carNo;
    }

    @Override
    protected String action() throws Exception {
        GoodPkApi api = new GoodPkApi().withAccessToken(this.mContext);
        return api.getCarWhere(this.mCarNo);
    }

    @Override
    protected CW parseData(String s) throws Exception {
        CarWhereParser parser = new CarWhereParser();

        //憑證錯誤
        if(s.contains("Certificate pinning failure!")){
            CW cw = new CW();
            cw.setResult_code("-99");
            return cw;
        }else{
            return parser.toData(s);
        }
    }
}
