package ru.nbch.credit_tracker.service.xml.stax;

import ru.nbch.credit_tracker.entities.external_response.errors.Error;
import ru.nbch.credit_tracker.entities.external_response.errors.InputParams;
import ru.nbch.credit_tracker.entities.external_response.errors.SgnlReport;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class SgnlReportStatusStaxReader extends BaseStaxReader<SgnlReport> {

    @Override
    public Class<SgnlReport> type() {
        return SgnlReport.class;
    }

    @Override
    protected SgnlReport createObject() {
        SgnlReport report = new SgnlReport();
        InputParams inputParams = new InputParams();
        report.setInputParams(inputParams);
        Error error = new Error();
        report.setError(error);
        return report;
    }

    @Override
    protected boolean innerProcess(XMLStreamReader reader, SgnlReport obj) {
        String text = buffer.toString();
        String currPath = getPath();
        switch (currPath) {
            case "/SgnlReport/InputParams/memberCode" ->
                obj.getInputParams().setMemberCode(text);
            case "/SgnlReport/Error/name" ->
                obj.getError().setName(text);
            case "/SgnlReport/Error/description" ->
                obj.getError().setDescription(text);
        }
        return false;
    }

    @Override
    protected void innerProcessStartElement(XMLStreamReader reader, SgnlReport obj) throws XMLStreamException {

    }
}
