package com.icomsys.main_vm.common.code;

import com.google.gson.Gson;
import com.icomsys.main_vm.common.code.enumresource.MenuResource;
import com.icomsys.main_vm.common.code.enumresource.PolicyResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.*;

@Component
@Slf4j
public class EnumToMap {

    public static final Map<String, List<String>> urlToMap = new HashMap<>();
    public static final Map<Long, MenuResource> MenuSeqToMenuMap = new HashMap<>();
    public static final Map<Long, MenuResource> MenuSeqUpperToMenuMap = new HashMap<>();
    public static final Map<Long, String> MenuSeqToPolicyMap = new HashMap<>();
    public static final Map<String, String> PolicyToMenuMap = new HashMap<>();
    public static final Map<String, String> PolicyToParentMap = new HashMap<>();
    public static final Map<String, List<MenuResource>> authToMap = new HashMap<>();
    public static final Map<Integer, String> spaceMap = new HashMap<>();
    @Order(0)
    @PostConstruct
    private void MenuSeqToMenuMap() {
        MenuResource.ALL.stream().forEach(e ->{
            MenuSeqToMenuMap.put(e.getMenuSeq(), e);
        });
    }

    @Order(1)
    @PostConstruct
    private void MenuSeqUpperToMenuMap() {
        MenuResource.ALL.stream().forEach(e ->{
            MenuSeqUpperToMenuMap.put(e.getMenuSeqUpper(), e);
        });
    }

    @Order(2)
    @PostConstruct
    private void MenuSeqToPolicyMap() {
        PolicyResource.ALL.stream().forEach(e ->{
            MenuSeqToPolicyMap.put(e.getMenu().getMenuSeq(), e.getName());
        });
    }

    @Order(3)
    @PostConstruct
    private void PolicyToMenuMap() {
        PolicyResource.ALL.stream().forEach(e ->{
            PolicyToMenuMap.put(e.getName(), e.getMenu().getMenuName());
        });
    }

    @Order(4)
    @PostConstruct
    private void PolicyToParentMap() {

        Map<Long, String> mstpm = new HashMap<>();

        PolicyResource.ALL.stream().forEach(e ->{
            mstpm.put(e.getMenu().getMenuSeq(), e.getName());
        });

        PolicyResource.ALL.stream().forEach(e ->{
            Long seqq = e.getMenu().getMenuSeqUpper();
            log.info(e.getName());
            if(seqq == 0L || seqq == 1L ){
                PolicyToParentMap.put(e.getName(), "#");
            }
            else {
                PolicyToParentMap.put(e.getName(), mstpm.get(seqq));
            }
        });
    }


    @PostConstruct
    private void WhiteSpace() {
        spaceMap.put(0, "");
        spaceMap.put(1, "   ");
        spaceMap.put(2, "      ");
        spaceMap.put(3, "         ");
        spaceMap.put(4, "            ");
        spaceMap.put(5, "               ");
    }



}
