package cn.novalon.gym.manage.db.converter;

import cn.novalon.gym.manage.sys.core.domain.SysPermission;
import cn.novalon.gym.manage.db.entity.SysPermissionEntity;

import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 权限实体转换器
 * 
 * @author 张翔
 * @date 2026-03-25
 */
@Component
public class SysPermissionConverter {

    public SysPermission toDomain(SysPermissionEntity entity) {
        if (entity == null) {
            return null;
        }
        SysPermission domain = new SysPermission();
        domain.setId(entity.getId());
        domain.setPermissionName(entity.getPermissionName());
        domain.setPermissionCode(entity.getPermissionCode());
        domain.setResource(entity.getResource());
        domain.setAction(entity.getAction());
        domain.setDescription(entity.getDescription());
        domain.setStatus(entity.getStatus());
        domain.setCreatedAt(entity.getCreatedAt());
        domain.setUpdatedAt(entity.getUpdatedAt());
        domain.setDeletedAt(entity.getDeletedAt());
        return domain;
    }

    public SysPermissionEntity toEntity(SysPermission domain) {
        if (domain == null) {
            return null;
        }
        SysPermissionEntity entity = new SysPermissionEntity();
        entity.setId(domain.getId());
        entity.setPermissionName(domain.getPermissionName());
        entity.setPermissionCode(domain.getPermissionCode());
        entity.setResource(domain.getResource());
        entity.setAction(domain.getAction());
        entity.setDescription(domain.getDescription());
        entity.setStatus(domain.getStatus());
        entity.setCreatedAt(domain.getCreatedAt());
        entity.setUpdatedAt(domain.getUpdatedAt());
        entity.setDeletedAt(domain.getDeletedAt());
        return entity;
    }

    public List<SysPermission> toDomainList(List<SysPermissionEntity> entities) {
        if (entities == null) {
            return null;
        }
        return entities.stream()
                .map(this::toDomain)
                .collect(Collectors.toList());
    }

    public List<SysPermissionEntity> toEntityList(List<SysPermission> domains) {
        if (domains == null) {
            return null;
        }
        return domains.stream()
                .map(this::toEntity)
                .collect(Collectors.toList());
    }
}