package edu.upvehu.gbg.xml.jaxb;

import javax.xml.bind.annotation.*;
import java.util.List;
import java.util.ArrayList;

@XmlAccessorType(XmlAccessType.FIELD)
public class Conversacion {

    @XmlAttribute(name = "id")
    private String id;

    @XmlAttribute(name = "contacto")
    private String contacto;

    // FIX PRINCIPAL: Inicializar la lista para evitar NullPointerException al llamar a getMensajes().isEmpty()
    @XmlElement(name = "mensaje", namespace = "http://www.example.com/chat")
    private List<Mensaje> mensajes = new ArrayList<>();

    // Getters y Setters
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getContacto() {
        return contacto;
    }

    public void setContacto(String contacto) {
        this.contacto = contacto;
    }

    public List<Mensaje> getMensajes() {
        return mensajes;
    }

    public void setMensajes(List<Mensaje> mensajes) {
        this.mensajes = mensajes;
    }
}