package de.cannamanage.service;

import de.cannamanage.domain.entity.StaffAccount;
import de.cannamanage.domain.enums.StaffPermission;

import java.util.EnumSet;
import java.util.Map;
import java.util.Set;

/**
 * Predefined permission templates for common staff roles.
 * Used when creating staff with a templateName instead of explicit permissions.
 */
public final class StaffTemplates {

    private StaffTemplates() {}

    private static final Map<String, Set<StaffPermission>> TEMPLATES = Map.of(
            "ausgabe", EnumSet.of(
                    StaffPermission.RECORD_DISTRIBUTION,
                    StaffPermission.VIEW_MEMBER_LIST,
                    StaffPermission.VIEW_MEMBER_QUOTA
            ),
            "lager", EnumSet.of(
                    StaffPermission.VIEW_STOCK,
                    StaffPermission.RECORD_STOCK_IN
            ),
            "vorstand", EnumSet.of(
                    StaffPermission.RECORD_DISTRIBUTION,
                    StaffPermission.VIEW_MEMBER_LIST,
                    StaffPermission.VIEW_MEMBER_QUOTA,
                    StaffPermission.ADD_MEMBER,
                    StaffPermission.VIEW_STOCK,
                    StaffPermission.RECORD_STOCK_IN,
                    StaffPermission.VIEW_COMPLIANCE_REPORT
                    // Note: MANAGE_GROW_CALENDAR excluded per plan
            )
    );

    /**
     * Returns the permission set for the given template name.
     * @throws IllegalArgumentException if template name is unknown
     */
    public static Set<StaffPermission> getTemplate(String name) {
        Set<StaffPermission> template = TEMPLATES.get(name.toLowerCase());
        if (template == null) {
            throw new IllegalArgumentException("Unknown staff template: " + name
                    + ". Available: " + TEMPLATES.keySet());
        }
        return EnumSet.copyOf(template);
    }

    public static Map<String, Set<StaffPermission>> getAllTemplates() {
        return TEMPLATES;
    }

    public static boolean exists(String name) {
        return TEMPLATES.containsKey(name.toLowerCase());
    }
}
