using SteUp.Shared.Core.Dto;

namespace SteUp.Maui.Core.Utility;

public static class UtilityFile
{
    public static async Task<AttachedDto> ConvertToDto(FileResult file, AttachedDto.TypeAttached type)
    {
        var stream = await file.OpenReadAsync();
        using var ms = new MemoryStream();
        await stream.CopyToAsync(ms);

        return new AttachedDto
        {
            Name = file.FileName,
            Path = file.FullPath,
            MimeType = file.ContentType,
            DimensionBytes = ms.Length,
            FileBytes = ms.ToArray(),
            Type = type
        };
    }
}