package com.pablotj.ai.chat.domain.model;

import java.util.Objects;
import java.util.UUID;

/**
 * Value Object representing a unique message identifier.
 */
public final class MessageId {

    private final String uuid;
    private Long id;

    public MessageId(Long id, String uuid) {
        this.id = Objects.requireNonNull(id, "Message ID cannot be null");
        this.uuid = Objects.requireNonNull(uuid, "Message UUID cannot be null");
    }

    private MessageId(String uuid) {
        this.uuid = Objects.requireNonNull(uuid, "Message UUID cannot be null");
    }

    public static MessageId generate() {
        return new MessageId(UUID.randomUUID().toString());
    }

    public static MessageId of(String value) {
        if (value == null || value.trim().isEmpty()) {
            throw new IllegalArgumentException("Message UUID cannot be null or empty");
        }
        return new MessageId(value.trim());
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUuid() {
        return uuid;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        MessageId messageId = (MessageId) obj;
        return Objects.equals(uuid, messageId.uuid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(uuid);
    }

    @Override
    public String toString() {
        return uuid;
    }
}
