package com.cool.store.vo.notice;

import com.cool.store.enums.notice.MatterTypeEnum;
import com.cool.store.enums.notice.ModuleCodeEnum;
import lombok.Data;

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

/**
 * @Author suzhuhong
 * @Date 2025/7/24 16:26
 * @Version 1.0
 */
@Data
public class ModuleAndMatterVO {

    private Integer moduleCode;

    private String moduleName;

    private List<MatterTypeVO> matterTypeList;

    public ModuleAndMatterVO(Integer moduleCode, String moduleName, List<MatterTypeVO> matterTypeList) {
        this.moduleCode = moduleCode;
        this.moduleName = moduleName;
        this.matterTypeList = matterTypeList;
    }

    @Data
    static  class MatterTypeVO{
        private Integer matterTypeCode;
        private String matterTypeName;
        public MatterTypeVO(Integer matterTypeCode, String matterTypeName) {
            this.matterTypeCode = matterTypeCode;
            this.matterTypeName = matterTypeName;
        }
    }

    public static List<ModuleAndMatterVO> getModuleAndMatterList() {
        return Arrays.stream(ModuleCodeEnum.values())
                .map(module -> new ModuleAndMatterVO(
                        module.getCode(),
                        module.getMessage(),
                        convertMatterTypes(module.getMatterTypeEnums())
                ))
                .collect(Collectors.toList());
    }

    private static List<MatterTypeVO> convertMatterTypes(List<MatterTypeEnum> matterTypeEnums) {
        return matterTypeEnums.stream()
                .map(matterType -> new MatterTypeVO(
                        matterType.getCode(),
                        matterType.getMessage()
                ))
                .collect(Collectors.toList());
    }
}
