package org.dromara.common.platform;


import cn.dev33.satoken.context.SaHolder;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

@Getter
@AllArgsConstructor(access= AccessLevel.PRIVATE)
public enum Platform {

    ADMIN(0,"PINGTAIDUAN","平台端"),
    MERCHANT(1,"SHANGHUDUAN","商户端");

    private final Integer id;
    private final String code;
    private final String label;

    public static boolean isAdmin(){
        return SaHolder.getContext().getRequest().getHeader(PlatformConstants.PLAFORM_HEADER).equals(ADMIN.code);
    }

    public static boolean isNotAdmin(){
        return !isAdmin();
    }

    public static boolean isAdmin(String header){
        return header.equals(ADMIN.code);
    }

    public static boolean isNotAdmin(String header){
        return !isAdmin(header);
    }

    public static Integer getIdByCode(String code){
        for (Platform value : values()) {
            if(value.code.equals(code)){
                return  value.id;
            }
        }
        throw new IllegalArgumentException("未知平台");
    }

//    public static List<PlatformInfo> list(){
//        return
//    }



}
