package cn.stylefeng.team.portal.modular.front.factory;

import cn.stylefeng.team.portal.modular.front.pojo.response.FrontAppLinkItem;
import cn.stylefeng.team.portal.modular.management.entity.PortalAppLink;
import cn.stylefeng.team.portal.modular.management.entity.PortalAppLinkCategory;

import java.util.ArrayList;
import java.util.List;

public class FrontAppLinkFactory {

    public static List<FrontAppLinkItem> buildAppLink(List<PortalAppLinkCategory> portalAppLinkCategoryList, List<PortalAppLink> portalAppLinkList) {
        List<FrontAppLinkItem> result = new ArrayList<>();
        for (PortalAppLinkCategory portalAppLinkCategory : portalAppLinkCategoryList) {
            FrontAppLinkItem frontAppLinkItem = new FrontAppLinkItem();
            frontAppLinkItem.setCategoryId(portalAppLinkCategory.getCategoryId());
            frontAppLinkItem.setCategoryName(portalAppLinkCategory.getCategoryName());
            frontAppLinkItem.setPortalAppLinkList(new ArrayList<>());

            for (PortalAppLink portalAppLink : portalAppLinkList) {
                if (portalAppLink.getLinkCategoryId().equals(portalAppLinkCategory.getCategoryId())) {
                    frontAppLinkItem.getPortalAppLinkList().add(portalAppLink);
                }
            }
            result.add(frontAppLinkItem);
        }
        return result;
    }

}
