using TakeoutSaaS.Application.Identity.Contracts;
using TakeoutSaaS.Domain.Identity.Entities;

namespace TakeoutSaaS.Application.Identity.Handlers;

/// <summary>
/// 模板 DTO 映射工具。
/// </summary>
internal static class TemplateMapper
{
    /// <summary>
    /// 将角色模板与权限编码集合映射为 DTO。
    /// </summary>
    /// <param name="template">角色模板实体。</param>
    /// <param name="permissionCodes">权限编码集合。</param>
    /// <returns>模板 DTO。</returns>
    public static RoleTemplateDto ToDto(RoleTemplate template, IReadOnlyCollection<string> permissionCodes)
    {
        return new RoleTemplateDto
        {
            TemplateCode = template.TemplateCode,
            Name = template.Name,
            Description = template.Description,
            IsActive = template.IsActive,
            Permissions = permissionCodes
                .Select(code => new PermissionTemplateDto
                {
                    Code = code,
                    Name = code,
                    Description = null
                })
                .ToArray()
        };
    }
}
