package cz.moneta.test.dsl.util.task.cebia;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.cebia.iva.WSAdministrativeDataType;
import cz.moneta.test.dsl.cebia.iva.WSVehicleType;
import cz.moneta.test.dsl.cebia.schemas.iva.service.VehicleIdentification1;
import cz.moneta.test.dsl.cebia.schemas.iva.service.VehicleIdentification1Response;
import cz.moneta.test.dsl.cebia.schemas.iva.service.WSHeaderType;
import cz.moneta.test.harness.support.auth.AuthSupport;
import cz.moneta.test.harness.support.auth.Credentials;

public class CebiaTasks {

    private final Harness harness;

    public CebiaTasks(Harness harness) {
        this.harness = harness;
    }

    public VehicleIdentification1Response verifyVehicle(String vin) {
        return harness.withCebia()
                .prepareRequest(prepareVehicleIdentification1Request(vin), VehicleIdentification1Response.class)
                .send();
    }

    private VehicleIdentification1 prepareVehicleIdentification1Request(String vin) {
        Credentials credentials = AuthSupport.getCredentials("iva-service", harness);
        return new VehicleIdentification1()
                .withHeader(new WSHeaderType()
                        .withUserName(credentials.getUsername())
                        .withUserPassword(credentials.getPassword()))
                .withVehicle(new WSVehicleType()
                        .withAdministrativeData(new WSAdministrativeDataType()
                                .withVIN(vin)));
    }
}
