using Lada.Framework.Data.Domains.Identity;
using Ladaer.BackEnd.Infrastructures.DTO.Models.Itentity;

namespace Ladaer.BackEnd.Infrastructures.Extensions
{
    public static class PermissionExtensions
    {
        /// <summary>
        /// Chuyển đổi từ PermissionModel sang Permission entity
        /// </summary>
        public static Permission ToEntity(this PermissionModel model)
        {
            return new Permission
            {
                Id = model.Id,
                Name = model.Name,
                Description = model.Description,
                IsActive = model.IsActive,
                CreatedTime = model.CreatedTime ?? DateTimeOffset.UtcNow,
                UpdatedTime = model.UpdatedTime ?? DateTimeOffset.UtcNow,
                CreatedBy = model.CreatedBy,
                CreatedByUserName = model.CreatedByUserName,
                UpdatedBy = model.UpdatedBy,
                UpdatedByUserName = model.UpdatedByUserName
            };
        }

        /// <summary>
        /// Chuyển đổi từ Permission entity sang PermissionModel
        /// </summary>
        public static PermissionModel ToModel(this Permission entity)
        {
            return new PermissionModel
            {
                Id = entity.Id,
                Name = entity.Name,
                Description = entity.Description,
                IsActive = entity.IsActive,
                CreatedTime = entity.CreatedTime,
                UpdatedTime = entity.UpdatedTime,
                CreatedBy = entity.CreatedBy,
                CreatedByUserName = entity.CreatedByUserName,
                UpdatedBy = entity.UpdatedBy,
                UpdatedByUserName = entity.UpdatedByUserName
            };
        }
    }
}
