package com.qqchen.deploy.backend.system.converter;

import com.qqchen.deploy.backend.system.entity.Menu;
import com.qqchen.deploy.backend.system.entity.Permission;
import com.qqchen.deploy.backend.framework.converter.BaseConverter;
import com.qqchen.deploy.backend.system.model.MenuDTO;
import com.qqchen.deploy.backend.system.model.response.MenuPermissionTreeResponse;
import com.qqchen.deploy.backend.system.model.response.MenuResponse;
import com.qqchen.deploy.backend.system.model.response.PermissionResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

@Mapper(config = BaseConverter.class)
public interface MenuConverter extends BaseConverter<Menu, MenuDTO> {

    @Override
    MenuDTO toDto(Menu entity);

    @Override
    List<MenuDTO> toDtoList(List<Menu> entityList);

    @Mapping(target = "children", expression = "java(toResponseList(dto.getChildren()))")
    MenuResponse toResponse(MenuDTO dto);

    List<MenuResponse> toResponseList(List<MenuDTO> dtoList);

    MenuPermissionTreeResponse toMenuPermissionResponse(Menu menu);

    PermissionResponse toPermissionResponse(Permission permission);

    List<PermissionResponse> toPermissionResponseList(List<Permission> permissions);
}