package com.xunhong.erp.turbo.rbac.infrastructure.convert;

import com.xunhong.erp.turbo.api.rbac.dto.cmd.RoleCreateCmd;
import com.xunhong.erp.turbo.api.rbac.dto.cmd.RoleUpdateCmd;
import com.xunhong.erp.turbo.rbac.domain.entity.Role;
import com.xunhong.erp.turbo.rbac.domain.entity.RolePermission;
import com.xunhong.erp.turbo.rbac.infrastructure.entity.RoleDO;
import com.xunhong.erp.turbo.rbac.infrastructure.entity.RolePermissionDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;

import java.util.List;

@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface RoleConvert {

	@Mapping(target = "rolePermissionList", source = "roleDO.rolePermissionDOList")
	@Mapping(target = "roleMenuList", source = "roleDO.roleMenuDOList")
	Role toRole(RoleDO roleDO);

	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "rolePermissionDOList", ignore = true)
	@Mapping(target = "roleMenuDOList", ignore = true)
	@Mapping(target = "roleId", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	RoleDO toRoleDO(RoleCreateCmd roleCreateCmd);

	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "rolePermissionDOList", ignore = true)
	@Mapping(target = "roleMenuDOList", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	RoleDO toRoleDO(RoleUpdateCmd roleUpdateCmd);

	@SuppressWarnings("unused")
	List<RolePermission> toRolePermissionDOList(List<RolePermissionDO> rolePermissionDOList);

	@SuppressWarnings("unused")
	RolePermission toRolePermission(RolePermissionDO rolePermissionDO);
}
