namespace OpenAI.Assistants;

public class MessageTextContentAnnotation
{
    private readonly MessageContentTextAnnotationsFileCitationObject _fileSearchCitation;
    private readonly MessageContentTextAnnotationsFilePathObject _codeCitation;

    /// <summary>
    /// The ID of the file cited by the <c>file_search</c> tool for this annotation.
    /// </summary>
    public string InputFileId => _fileSearchCitation?.FileCitation?.FileId;

    /// <summary>
    /// The ID of the file that was generated by the <c>code_interpreter</c> tool for this citation.
    /// </summary>
    public string OutputFileId => _codeCitation?.FilePath?.FileId;

    /// <summary>
    /// The index in the message content at which the citation begins.
    /// </summary>
    public int StartIndex => _fileSearchCitation?.StartIndex ?? _codeCitation?.StartIndex ?? -1;

    /// <summary>
    /// The index in the message content at which the citation ends.
    /// </summary>
    public int EndIndex => _fileSearchCitation?.EndIndex ?? _codeCitation?.EndIndex ?? -1;

    /// <summary>
    /// The text in the message content that should be replaced.
    /// </summary>
    public string TextToReplace => _fileSearchCitation?.Text ?? _codeCitation?.Text;

    internal MessageTextContentAnnotation(MessageContentTextObjectAnnotation internalAnnotation)
    {
        _fileSearchCitation = internalAnnotation as MessageContentTextAnnotationsFileCitationObject;
        _codeCitation = internalAnnotation as MessageContentTextAnnotationsFilePathObject; ;
    }
}