using AnthropicClient.Utils;
namespace AnthropicClient.Models;
///
/// Represents a request to create a file via the Anthropic Files API.
///
public class CreateFileRequest
{
///
/// The file content as a byte array.
///
public byte[] File { get; init; }
///
/// The original filename of the file being uploaded.
///
public string FileName { get; init; }
///
/// The MIME type of the file.
///
public string FileType { get; init; }
///
/// Initializes a new instance of the class.
///
/// The file content as a byte array.
/// The original filename of the file being uploaded.
/// The MIME type of the file.
/// Thrown when is null.
/// Thrown when or is null or whitespace.
public CreateFileRequest(byte[] file, string fileName, string fileType)
{
ArgumentValidator.ThrowIfNull(file, nameof(file));
ArgumentValidator.ThrowIfNullOrWhitespace(fileName, nameof(fileName));
ArgumentValidator.ThrowIfNullOrWhitespace(fileType, nameof(fileType));
File = file;
FileName = fileName;
FileType = fileType;
}
///
/// Initializes a new instance of the class from a stream.
///
/// The stream containing the file content.
/// The original filename of the file being uploaded.
/// The MIME type of the file.
/// Thrown when is null.
/// Thrown when or is null or whitespace.
public CreateFileRequest(Stream stream, string fileName, string fileType)
{
ArgumentValidator.ThrowIfNull(stream, nameof(stream));
ArgumentValidator.ThrowIfNullOrWhitespace(fileName, nameof(fileName));
ArgumentValidator.ThrowIfNullOrWhitespace(fileType, nameof(fileType));
using var memoryStream = new MemoryStream();
stream.CopyToAsync(memoryStream);
var fileContent = memoryStream.ToArray();
File = fileContent;
FileName = fileName;
FileType = fileType;
}
}