namespace Journal.Core.Models;

public class ConversationMessage
{
    public Guid Id { get; }
    public Guid ConversationId { get; }
    public string Role { get; set; }
    public string Text { get; set; }
    public DateTimeOffset CreatedAt { get; set; }

    public ConversationMessage(Guid conversationId, string role, string text)
    {
        if (conversationId == Guid.Empty)
            throw new ArgumentException("ConversationId is required", nameof(conversationId));
        if (string.IsNullOrWhiteSpace(role))
            throw new ArgumentException("Role is required", nameof(role));
        if (string.IsNullOrWhiteSpace(text))
            throw new ArgumentException("Text is required", nameof(text));

        Id = Guid.NewGuid();
        ConversationId = conversationId;
        Role = role.Trim();
        Text = text;
        CreatedAt = DateTimeOffset.Now;
    }

    public ConversationMessage(Guid id, Guid conversationId, string role, string text, DateTimeOffset createdAt)
    {
        if (id == Guid.Empty)
            throw new ArgumentException("Id is required", nameof(id));

        Id = id;
        ConversationId = conversationId;
        Role = role;
        Text = text;
        CreatedAt = createdAt;
    }
}
