package tw.com.altob.goodpk.Loader;

import android.content.Context;
import android.widget.Switch;

import androidx.annotation.NonNull;

import com.ga.sdk.loader.BaseAsyncTaskLoader;

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

public class GetCarSecurityLoader extends BaseAsyncTaskLoader<CS> {

    private String Acct, Pwd, Status, Key, station;
    private Context mContext;

    public GetCarSecurityLoader(@NonNull Context context, String mAcct, String mPwd, String mStatus, String mkey, String station) {
        super(context);

        this.mContext = context;
        this.Acct = mAcct;
        this.Pwd = mPwd;
        this.Status = mStatus;
        this.Key = mkey;
        this.station = station;
    }

    @Override
    protected String action() throws Exception {
        GoodPkApi api = new GoodPkApi().withAccessToken(this.mContext);
        return api.getCarSecurity(this.Acct, this.Pwd, this.Status, this.Key, this.station);
    }

    @Override
    protected CS parseData(String s) throws Exception {
        CarSecurityParser parser = new CarSecurityParser();

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