using System;
using MongoDB.Bson.Serialization.Attributes;

namespace Knot.Modules.Messaging.Domain;

[BsonDiscriminator("StoryMessage")]
public class StoryMessage : Message
{
    public override string Type => "story";
    public override string? Content { get; protected set; }
    
    public Guid InternalStoryId { get; private set; }
    public Guid? StoryId => InternalStoryId;
    
    public string InternalStoryMediaUrl { get; private set; }
    public string? StoryMediaUrl => InternalStoryMediaUrl;
    
    public MediaType InternalStoryMediaType { get; private set; }
    public string? StoryMediaType => InternalStoryMediaType.ToString().ToLower();

    private StoryMessage() : base() 
    { 
        InternalStoryMediaUrl = string.Empty;
        InternalStoryMediaType = MediaType.Image;
    }

    public StoryMessage(
        Guid id, 
        Guid chatId, 
        Guid senderId,
        Guid storyId,
        string storyMediaUrl,
        MediaType storyMediaType,
        string? content,
        Guid? replyToId, 
        Guid? forwardedFromId, 
        DateTime createdAt, 
        bool isImported) 
        : base(id, chatId, senderId, replyToId, forwardedFromId, createdAt, isImported)
    {
        InternalStoryId = storyId;
        InternalStoryMediaUrl = storyMediaUrl;
        InternalStoryMediaType = storyMediaType;
        Content = content;

        if (!isImported) 
        {
            RaiseDomainEvent(new MessageSentDomainEvent(Id, ChatId, SenderId, Content));
        }
    }

    public override void Delete()
    {
        Content = null;
        base.Delete();
    }
}


