using Butter.Dtos.Asset;
using Butter.Types;
using Lactose.Models;

namespace Lactose.Mapper;

/// <summary>
/// Provides mapping methods for converting Asset objects to DTOs.
/// </summary>
public static class AssetsMapper {
    /// <summary>
    /// Maps an Asset object to a GetFullAssetDto object.
    /// </summary>
    /// <param name="asset">The asset to map.</param>
    /// <param name="accessLevel">The access level of the user.</param>
    /// <returns>A GetFullAssetDto object.</returns>
    public static AssetDto ToFullAssetsDto(this Asset asset, EAccessLevel accessLevel) => new AssetDto {
        Id        = asset.Id,
        FileName  = accessLevel >= EAccessLevel.Curator ? asset.OriginalFilename : null,
        AssetType = asset.Type,
        IsPublic  = asset.IsPubliclyShared,
        CreatedAt = asset.CreatedAt,
        UpdatedAt = asset.UpdatedAt,
        DeletedAt = asset.DeletedAt,
        Owner     = asset.Owner!.ToGetUsersDto(),
        MimeType  = asset.MimeType,
        ResolutionWidth = asset.ResolutionWidth,
        ResolutionHeight = asset.ResolutionHeight,
        FileSize = asset.FileSize,
        Duration = asset.Duration ?? 0,
        FrameRate = asset.FrameRate ?? 0
    };

    /// <summary>
    /// Maps an Asset object to a GetAssetPreviewDto object.
    /// </summary>
    /// <param name="asset">The asset to map.</param>
    /// <returns>A GetAssetPreviewDto object.</returns>
    public static AssetPreviewDto ToAssetPreviewDto(this Asset asset) => new AssetPreviewDto {
        Id = asset.Id,
        MimeType = asset.MimeType
    };

    /// <summary>
    /// Maps a collection of Asset objects to a collection of GetAssetPreviewDto objects.
    /// </summary>
    /// <param name="assets">The collection of assets to map.</param>
    /// <returns>A collection of GetAssetPreviewDto objects.</returns>
    public static IEnumerable<AssetPreviewDto> ToAssetPreviewDto(this IEnumerable<Asset> assets)
        => assets.Select(ToAssetPreviewDto);
}