from .constants import MAX_LEVEL, MAX_RATING, MIN_LEVEL, MIN_RATING, STAFF_ROLES
from .exceptions import StaffCapabilityInvalidError, StaffRoleInvalidError


def validate_role(role):
    if role not in STAFF_ROLES:
        raise StaffRoleInvalidError("Unsupported staff role.")
    return role


def validate_capabilities(*, level, leadership, tactical, development, fitness, goalkeeping):
    if not MIN_LEVEL <= int(level) <= MAX_LEVEL:
        raise StaffCapabilityInvalidError("Staff level must be between 1 and 5.")
    values = {
        "leadership": leadership,
        "tactical": tactical,
        "development": development,
        "fitness": fitness,
        "goalkeeping": goalkeeping,
    }
    for name, value in values.items():
        if not MIN_RATING <= int(value) <= MAX_RATING:
            raise StaffCapabilityInvalidError(f"{name} must be between 1 and 100.")
    return {"level": int(level), **{k: int(v) for k, v in values.items()}}
