using Butter.Dtos.Settings;
using Lactose.Models;

namespace Lactose.Mapper;

/// <summary>
/// Extension methods for the Settings class.
/// </summary>
public static class SettingsMapper {
    /// <summary>
    /// Converts a Settings object to a SettingsDto object.
    /// </summary>
    /// <param name="setting">The Settings object to convert.</param>
    /// <returns>A SettingsDto object.</returns>
    public static SettingDto ToSettingDto(this Setting setting) => new SettingDto {
        Name = setting.Name,
        Value = setting.Value
    };
    
    /// <summary>
    /// Converts a SettingsDto object to a Settings object.
    /// </summary>
    /// <returns>A Settings object.</returns>
    public static Setting ToSetting(this SettingDto settingDto) => new Setting {
        Name  = settingDto.Name,
        Value = settingDto.Value
    };
    
    public static SettingsDto ToSettingsDto(this IEnumerable<Setting> settings) => new SettingsDto {
        Settings = settings.Select(s => s.ToSettingDto())
    };
}