public static function parseAPI(BitRank $bitrank, $flag_data)
    {
        $flags = [];
        foreach ($flag_data as $key => $value) {
            $slug = isset($value['flag']) ? $value['flag'] : $key;
            
            switch (self::requireValue($value, 'type')) {
                case Flag::TYPE_GOOD:      $type = Flag::TYPE_GOOD;       break;
                case Flag::TYPE_NEUTRAL:   $type = Flag::TYPE_NEUTRAL;    break;
                case Flag::TYPE_BAD:       $type = Flag::TYPE_BAD;        break;
                default:
                    throw new InvalidDataException("Invalid type '$value[type]' returned for flag '$slug'");
            }

            switch (self::requireValue($value, 'impact')) {
                case Flag::IMPACT_HIGH:   $impact = Flag::IMPACT_HIGH;      break;
                case Flag::IMPACT_MEDIUM: $impact = Flag::IMPACT_MEDIUM;    break;
                case Flag::IMPACT_LOW:    $impact = Flag::IMPACT_LOW;       break;
                default:
                    throw new InvalidDataException("Invalid impact '$value[impact]' returned for flag '$slug'");
            }

            $flags[$slug] = new Flag($bitrank, $slug, $type, $impact);
        }

        return $flags;
    }