package ru.nbch.credit_tracker.entities.external_response.monitoring_report_error;

import jakarta.xml.bind.annotation.*;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Setter
@Getter
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
        "id",
        "version",
        "user",
        "reportCreated"
})
@XmlRootElement(name = "Errors")
public class MonitoringReportErrors {

    @XmlElement(name = "Id")
    protected String id;

    @XmlElement(name = "Version")
    protected String version;

    @XmlElement(name = "User")
    protected String user;

    @XmlElement(name = "ReportCreated")
    protected String reportCreated;

    @XmlElement(name = "p")
    protected List<P> persons;

    public List<P> getPersons() {
        if (persons == null) {
            persons = new ArrayList<>();
        }
        return this.persons;
    }

    private P currentPerson;

    public void createCurrentPerson() {
        currentPerson = new P();
    }

    public P getCurrentPerson() {
        return currentPerson;
    }

    public void finalizePerson() {
        getPersons().add(currentPerson);
    }

    @Getter
    @Setter
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
    })
    public static class P {

        @XmlAttribute(name = "uid")
        protected Integer uid;

        @XmlValue
        protected String value;

    }
}
